public async Task <bool> CreateExpense(ExpenseCreate request) { var entity = _mapper.Map <Expense>(request); await _midasContext.Expense.AddAsync(entity); return(await _midasContext.SaveChangesAsync() == 1); }
public bool CreateCategory(ExpenseCreate model) { var categoryEntity = new Category() { Name = model.CategoryName, Type = model.CategoryType, UserId = _userId }; using (var context = new ApplicationDbContext()) { context.Categories.Add(categoryEntity); return(context.SaveChanges() == 1); } }
public ActionResult Create(ExpenseCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateExpenseService(); if (service.CreateExpense(model)) { TempData["SaveResult"] = "Your expense was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Expense could not be created."); return(View(model)); }
public async Task <IActionResult> Create(ExpenseCreate request) { try { if (await _expenseService.CreateExpense(request)) { TempData["SaveResult"] = "Your invoice was created!"; return(RedirectToAction("Index")); } throw new Exception(); } catch { ModelState.AddModelError("", "Invoice was unable to be created"); return(View(request)); } }
public ActionResult CreateExpense(ExpenseCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateExpenseService(); if (service.CreateExpense(model)) { TempData["SaveResult"] = "Your expense has been created!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "The expense could not be created. The event ID you entered may be invalid."); return(View(model)); }
public bool CreateExpense(ExpenseCreate model) { var entity = new Expense() { OwnerId = _userId, ExpenseType = model.ExpenseType, Description = model.Description, Budget = model.Budget, ActualAmount = model.ActualAmount, PaymentMethod = model.PaymentMethod, EventId = model.EventId }; using (var ctx = new ApplicationDbContext()) { ctx.Expenses.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateDueDates(ExpenseCreate model) { int frequencyFactor = model.FrequencyFactor ?? 1; if (model.CategoryType == CategoryType.Once) { model.ExpenseFreqType = ExpenseFreqType.Once; } // the only time model.InitialDueDate won't be filled out by user is if model.CategoryType == CategoryType.Expense, // in which case, start the due date on the last day of the current month DateTime lastDayCurrentMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); DateTime initialDueDate = model.InitialDueDate ?? lastDayCurrentMonth; if (model.ExpenseFreqType == ExpenseFreqType.ByWeek && model.CategoryType == CategoryType.Expense) { initialDueDate = DateTime.Now; } DateTime endDate = model.EndDate ?? new DateTime(2035, 12, 31); if (model.CategoryType == CategoryType.Once) { endDate = initialDueDate; } var dueDates = new List <DateTime>(); if (model.ExpenseFreqType == ExpenseFreqType.ByMonth) { for (var date = initialDueDate; (DateTime.Compare(date, endDate)) <= 0; date = date.AddMonths(1 * frequencyFactor)) { dueDates.Add(date); } } else if (model.ExpenseFreqType == ExpenseFreqType.ByWeek) { for (var date = initialDueDate; (DateTime.Compare(date, endDate)) <= 0; date = date.AddDays(7 * frequencyFactor)) { dueDates.Add(date); } } else { dueDates.Add(initialDueDate); } using (var context = new ApplicationDbContext()) { foreach (var date in dueDates) { var dueDateEntity = new DueDate() { ExpenseId = (context.Categories.Single(c => c.Name == model.CategoryName && c.UserId == _userId)).Id, MonthId = (context.Months.Single(m => m.BeginDate.Month == date.Month && m.BeginDate.Year == date.Year && m.UserId == _userId)).Id, Date = date, Amount = model.Amount, UserId = _userId }; context.DueDates.Add(dueDateEntity); } return(context.SaveChanges() == dueDates.Count()); } }
public bool CreateExpense(ExpenseCreate model) { var categoryService = CreateCategoryService(); if (!categoryService.CreateCategory(model)) { return(false); } int frequencyFactor = model.FrequencyFactor ?? 1; if (model.CategoryType == CategoryType.Once) { model.ExpenseFreqType = ExpenseFreqType.Once; } // the only time model.InitialDueDate won't be filled out by user is if model.CategoryType == CategoryType.Expense, // in which case, start the due date on the last day of the current month DateTime lastDayCurrentMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); DateTime initialDueDate = model.InitialDueDate ?? lastDayCurrentMonth; if (model.ExpenseFreqType == ExpenseFreqType.ByWeek && model.CategoryType == CategoryType.Expense) { initialDueDate = DateTime.Now; } DateTime endDate = model.EndDate ?? new DateTime(2035, 12, 31); if (model.CategoryType == CategoryType.Once) { endDate = initialDueDate; } using (var context = new ApplicationDbContext()) { var expenseEntity = new Expense() { Id = (context.Categories.Single(c => c.Name == model.CategoryName && c.UserId == _userId)).Id, Amount = model.Amount, ExpenseFreqType = model.ExpenseFreqType, FrequencyFactor = frequencyFactor, InitialDueDate = initialDueDate, EndDate = endDate, UserId = _userId }; context.Expenses.Add(expenseEntity); if (!(context.SaveChanges() == 1)) { return(false); } } var dueDateService = CreateDueDateService(); if (!dueDateService.CreateDueDates(model)) { return(false); } return(true); }
public async Task<ExpenseCreate.response> ExpenseCreate(ExpenseCreate.request request, CancellationToken? token = null) { return await SendAsync<ExpenseCreate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None)); }