public ActionResult Create(SectionUpdateViewModel viewModel) { try { if (ModelState.IsValid) { SectionEntity section = new SectionEntity() { Name = viewModel.Name, Info = viewModel.Description, }; sectionService.Create(section); return RedirectToAction("Index"); } } catch (InvalidOperationException e) { logger.Error(e.Message, e); return View("Error"); } return View(); }
public ActionResult Edit(int id) { var section = sectionService.GetEntity(id); if (section == null) { return View("Error"); } SectionUpdateViewModel model = new SectionUpdateViewModel() { Name = section.Name, Description = section.Info }; return View(model); }
public ActionResult Edit(int id, SectionUpdateViewModel viewModel) { try { if (ModelState.IsValid) { SectionEntity section = new SectionEntity() { Id = id, Name = viewModel.Name, Info = viewModel.Description, }; sectionService.Update(section); return RedirectToAction("Index"); } return RedirectToAction("Index"); } catch { return View(viewModel); } }