public ActionResult Create(MonthlyFinanceCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateMonthlyFinanceService(); if (service.CreateMonthlyFinance(model)) { TempData["SaveResult"] = "Your monthly finances have been saved."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Finances could not be saved."); return(View(model)); }
public bool CreateMonthlyFinance(MonthlyFinanceCreate model) { var entity = new MonthlyFinance() { UserID = _userID, MonthlyFinanceID = model.MonthlyFinanceID, Month = model.Month, Year = model.Year, MonthlyTakeHome = model.MonthlyTakeHome, CostOfBills = model.CostOfBills, GoalItemID = model.GoalItemID, CreatedUTC = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.MonthlyFinances.Add(entity); return(ctx.SaveChanges() == 1); } }