public async Task <bool> UpdateInvestor(InvestorEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Investors .Single(i => i.InvestorID == model.InvestorID && i.OwnerID == _userId); entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.Address = model.Address; entity.City = model.City; entity.State = model.State; entity.Email = model.Email; entity.PhoneNumber = model.PhoneNumber; return(await ctx.SaveChangesAsync() == 1); } }
public async Task <ActionResult> Edit(int id) { var service = CreateInvestorService(); var detail = await service.GetInvestorByID(id); var model = new InvestorEdit { InvestorID = detail.InvestorID, FirstName = detail.FirstName, LastName = detail.LastName, Address = detail.Address, City = detail.City, State = detail.State, Email = detail.Email, PhoneNumber = detail.PhoneNumber }; return(View(model)); }
public async Task <ActionResult> Edit(int id, InvestorEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.InvestorID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateInvestorService(); if (await service.UpdateInvestor(model)) { TempData["SaveResult"] = "The investor was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The investor could not be updated."); return(View()); }