public ActionResult Edit(int id) { var service = CreateDIYService(); var detail = service.GetDIYById(id); var model = new DIYEdit { DIYId = detail.DIYId, ProjectName = detail.ProjectName, StartDate = detail.StartDate, EndDate = detail.EndDate, BudgetedAmount = detail.BudgetedAmount, FinalCost = detail.FinalCost }; return(View(model)); }
public bool UpdateDIY(DIYEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .DIYs .Single(e => e.DIYId == model.DIYId && e.OwnerId == _userId); entity.ProjectName = model.ProjectName; entity.StartDate = model.StartDate; entity.EndDate = model.EndDate; entity.BudgetedAmount = model.BudgetedAmount; entity.FinalCost = model.FinalCost; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, DIYEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.DIYId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateDIYService(); if (service.UpdateDIY(model)) { TempData["SaveResult"] = "Your project was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your project could not be updated."); return(View(model)); }