public ActionResult Edit(VMAnnouncementEdit model) { int selectedAnnouncementId = Convert.ToInt32(Session["SelectedAnnouncementId"]); Announcement announcement = _uow.AnnouncementManager.Get(x => x.AnnouncementId == selectedAnnouncementId); announcement.Title = model.Title; announcement.Body = model.Body; announcement.IsImportant = model.IsImportant; var result = _uow.AnnouncementManager.Update(announcement); Session.Remove("SelectedAnnouncementId"); if (_uow.SaveChanges()) { TempData["ProcessResult"] = "Announcement updated successfully."; TempData["AlertType"] = "success"; return(RedirectToAction("List")); } else { TempData["ProcessResult"] = "An enexpected error occurred while updating the announcement."; TempData["AlertType"] = "danger"; return(RedirectToAction("List")); } }
public ActionResult Edit(int id) { Session["SelectedAnnouncementId"] = id; // Created to capture in post method when data is sent. Announcement announcement = _uow.AnnouncementManager.Get(x => x.AnnouncementId == id); if (announcement == null) { TempData["ProcessResult"] = "There was an error while viewing the announcement."; TempData["AlertType"] = "danger"; return(RedirectToAction("List")); } VMAnnouncementEdit vmAnnouncementEdit = VMAnnouncementEdit.Parse(announcement); return(View(vmAnnouncementEdit)); }