Пример #1
0
        public ActionResult Edit(int id)
        {
            var category = newsCategoryRepository.Get(id);
            var newsCategoryViewModel = new NewsCategoryFormViewModel
            {
                Id = category.Id,
                Name = category.Name,
            };

            return View(newsCategoryViewModel);
        }
Пример #2
0
        public ActionResult Create(NewsCategoryFormViewModel newsCategoryViewModel)
        {
            if (ViewData.ModelState.IsValid)
            {
                var newsCategory = new NewsCategory(newsCategoryViewModel.Name);
                newsCategoryRepository.SaveOrUpdate(newsCategory);
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = "The news category was successfully created.";
                return RedirectToAction("Index");
            }

            return View(newsCategoryViewModel);
        }
Пример #3
0
        public ActionResult Edit(NewsCategoryFormViewModel newsCategoryViewModel)
        {
            var news = newsCategoryRepository.Get(newsCategoryViewModel.Id);

            if (ViewData.ModelState.IsValid)
            {
                news.Name = newsCategoryViewModel.Name;
                newsCategoryRepository.SaveOrUpdate(news);
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = "The news was successfully updated.";
                return RedirectToAction("Index");
            }

            newsCategoryRepository.DbContext.RollbackTransaction();
            return View(newsCategoryViewModel);
        }
Пример #4
0
 public ActionResult Create()
 {
     var newsViewModel = new NewsCategoryFormViewModel();
     return View(newsViewModel);
 }