public ActionResult Edit(int id, LoanEdit model) { var userID = Guid.Parse(User.Identity.GetUserId()); var svc = new GeckoService(userID); ViewBag.LoanedGeckoID = new SelectList(svc.GetGeckos(), "GeckoID", "GeckoName", model.LoanedGeckoID); if (!ModelState.IsValid) { return(View(model)); } if (model.LoanID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateLoanService(); if (service.UpdateLoan(model)) { TempData["SaveResult"] = "Loan information was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Loan information could not be updated."); return(View(model)); }
public bool UpdateLoan(LoanEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Loans .Single(e => e.LoanID == model.LoanID && e.OwnerID == _userID); entity.LoanID = model.LoanID; entity.LoanedGeckoID = model.LoanedGeckoID; entity.LoanedGeckoName = model.LoanedGeckoName; entity.LeaseeName = model.LeaseeName; entity.LoanStart = model.LoanStart; entity.LoanDuration = model.LoanDuration; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var userID = Guid.Parse(User.Identity.GetUserId()); var svc = new GeckoService(userID); var service = CreateLoanService(); var detail = service.GetLoanByID(id); var model = new LoanEdit { LoanID = detail.LoanID, LoanedGeckoID = detail.LoanedGeckoID, LoanedGeckoName = detail.LoanedGeckoName, LeaseeName = detail.LeaseeName, LoanStart = detail.LoanStart, LoanDuration = detail.LoanDuration }; ViewBag.LoanedGeckoID = new SelectList(svc.GetGeckos(), "GeckoID", "GeckoName", model.LoanedGeckoID); return(View(model)); }