Beispiel #1
0
 public ActionResult Edit(EditCategoryProdViewModel editCategory)
 {
     if (ModelState.IsValid)
     {
         int result = _productProvider.EditCategory(editCategory);
         if (result == 0)
         {
             ModelState.AddModelError("", "Помилка збереження даних!");
         }
         else if (result != 0)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(editCategory));
 }
Beispiel #2
0
        public EditCategoryProdViewModel EditCategory(int id)
        {
            EditCategoryProdViewModel model = null;

            var category = _categoryRepository.GetCategoryById(id);

            if (category != null)
            {
                model = new EditCategoryProdViewModel
                {
                    Id        = category.Id,
                    Name      = category.Name,
                    Published = category.Published
                };
            }
            return(model);
        }
Beispiel #3
0
 public int EditCategory(EditCategoryProdViewModel editCategory)
 {
     try
     {
         var category =
             _categoryRepository.GetCategoryById(editCategory.Id);
         if (category != null)
         {
             category.Name      = editCategory.Name;
             category.Published = editCategory.Published;
             _categoryRepository.SaveChanges();
         }
     }
     catch
     {
         return(0);
     }
     return(editCategory.Id);
 }