public ActionResult Edit(int id) { var service = CreateBillService(); var detail = service.GetBillById(id); var model = new BillEdit { BillingID = detail.BillingID, DateIssued = detail.DateIssued, DateDue = detail.DateDue, BillStatus = detail.BillStatus, BillAmount = detail.BillAmount, ClientId = detail.ClientId, }; return(View(model)); }
public bool UpdateBill(BillEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Bills .Single(e => e.BillingID == model.BillingID && e.OwnerID == _userId); entity.DateIssued = model.DateIssued; entity.DateDue = model.DateDue; entity.BillStatus = model.BillStatus; entity.BillAmount = model.BillAmount; entity.ClientId = model.ClientId; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, BillEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.BillingID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateBillService(); if (service.UpdateBill(model)) { TempData["SaveResult"] = "Your bill was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your bill could not be updated."); return(View(model)); }