public ActionResult Edit(int id) { var service = CreateCigarTypeService(); var detail = service.GetCigarTypeById(id); var model = new CigarTypeEdit { CigarTypeName = detail.CigarTypeName, }; return(View(model)); }
public bool UpdateCigarType(CigarTypeEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .CigarTypes .Single(e => e.CigarTypeId == model.CigarTypeId); if (entity.CigarTypeName == model.CigarTypeName) { return(true); } { entity.CigarTypeId = model.CigarTypeId; entity.CigarTypeName = model.CigarTypeName; } return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, CigarTypeEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.CigarTypeId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateCigarTypeService(); if (service.UpdateCigarType(model)) { TempData["SaveResult"] = "Your cigar type was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your cigar type could not be updated."); return(View()); }