public async Task <ActionResult> Create(AcctCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateAcctService(); if (await service.CreateAcct(model)) { TempData["SaveResult"] = "The account was successfully created"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The account could not be created."); return(View(model)); }
public async Task <bool> CreateAcct(AcctCreate model) { var entity = new Acct() { OwnerID = _userId, AcctName = model.AcctName, AcctType = (Acct.AcctTypeEnum)model.AcctType, TotalValue = model.TotalValue, OpenedUtc = DateTimeOffset.Now, InvestorID = model.InvestorID }; using (var ctx = new ApplicationDbContext()) { ctx.Accts.Add(entity); return(await ctx.SaveChangesAsync() == 1); } }