public ActionResult EditSubPage(SubPageViewModel viewModel) { if (ModelState.IsValid) { using (new UnitOfWork(_currentContext)) { var existing = staticPagesRepository.GetSubPageById(viewModel.Id); existing.Title = viewModel.Title; existing.Content = viewModel.Content; existing.Key = viewModel.Key; existing.Account = accountRepository.GetByUsername(CurrentUserName); existing.IsManual = viewModel.IsManual; } TempData[Const.ActionResultInfo] = "Подстраница успешно изменена"; return RedirectToAction("ManageStaticPage", new { id = viewModel.StaticPageId }); } TempData[Const.ActionErrorInfo] = "Ошибка редактирования. Проверьте правильность введенных данных"; return RedirectToAction("ManageStaticPage", new { id = viewModel.StaticPageId }); }
public ActionResult AddSubPage(SubPageViewModel viewModel) { if (ModelState.IsValid) { using (new UnitOfWork(_currentContext)) { var subPage = new StaticSubPage() { Title = viewModel.Title, Content = viewModel.Content, Account = accountRepository.GetByUsername(CurrentUserName), IsManual = viewModel.IsManual, IsSystem = viewModel.IsSystem, Key = viewModel.Key, StaticPageId = viewModel.StaticPageId, Section = (int)viewModel.Section }; var page = staticPagesRepository.GetById(viewModel.StaticPageId); page.SubPages.Add(subPage); TempData[Const.ActionResultInfo] = "Страница успешно добавлена"; return RedirectToAction("ManageStaticPage", new { id = viewModel.StaticPageId }); } } TempData[Const.ActionErrorInfo] = "Ошибка добавления страницы. Проверьте правильность введенных данных"; return RedirectToAction("ManageStaticPage", new { id = viewModel.StaticPageId }); }
public ActionResult EditSubPage(int id) { var subpage = staticPagesRepository.GetSubPageById(id); if (subpage == null) { TempData[Const.ActionErrorInfo] = "Подстраница не найдена"; return RedirectToAction("Index"); } var viewModel = new SubPageViewModel { Id = subpage.Id, Title = subpage.Title, Content = subpage.Content, IsManual = subpage.IsManual, IsSystem = subpage.IsSystem, Key = subpage.Key, Section = (StaticPageSection)subpage.Section, StaticPageId = subpage.StaticPageId }; ViewBag.StaticPageName = subpage.MainPage.Title; return View(viewModel); }
public ActionResult AddSubPage(int id) { var page = staticPagesRepository.GetById(id); if (page == null) { TempData[Const.ActionErrorInfo] = "Страница не найдена"; return RedirectToAction("Index"); } var viewModel = new SubPageViewModel() { IsManual = page.IsManual, IsSystem = page.IsSystem, Section = (StaticPageSection)page.Section, StaticPageId = id }; ViewBag.StaticPageName = page.Title; return View(viewModel); }