public ActionResult Edit(int id, UEdit model) { var svc = CreateUnethicalService(); try { if (!ModelState.IsValid) { return(View(model)); } else if (svc.UpdateUnethicalOrganization(model, id)) { TempData["SaveResult"] = " Your organization was updated."; return(RedirectToAction("Index")); } } catch { if (model.UnethicalOrganizationId != id) { ModelState.AddModelError("", "Unethical Organization ID Missmatch"); return(View(model)); } } return(View(model)); }
// Update // GET: Edit (Update) // Unethical/Edit/{id} public ActionResult Edit(int id) { var service = CreateUnethicalService(); var detail = service.GetUnethicalOrganizationById(id); var model = new UEdit { UnethicalOrganizationName = detail.UnethicalOrganizationName, FastFashion = detail.FastFashion, Exploitation = detail.Exploitation, Sweatshop = detail.Sweatshop, Copyright = detail.Copyright, UCountry = detail.UCountry, UImprove = detail.UImprove }; return(View(model)); }
// Update public bool UpdateUnethicalOrganization(UEdit model, int id) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .UnethicalOrganizations .Single(e => e.UnethicalOrganizationId == id && e.Id == _userId); entity.UnethicalOrganizationName = model.UnethicalOrganizationName; entity.FastFashion = model.FastFashion; entity.Exploitation = model.Exploitation; entity.Sweatshop = model.Sweatshop; entity.Copyright = model.Copyright; entity.UCountry = model.UCountry; entity.UImprove = model.UImprove; return(ctx.SaveChanges() == 1); } }