public ActionResult Create() { CategoryCRUDViewModel model = new CategoryCRUDViewModel(); model.ParentCategories = ParentCategorySevices.Instance.GetAllParentCategories(); return(PartialView(model)); }
public ActionResult Edit(int id) { try { var model = new CategoryCRUDViewModel(); var category = CategoriesService.Instance.GetCategoryById(id); model.ID = category.ID; model.ParentCategoryID = category.ParentCategoryID; model.ParentCategories = ParentCategorySevices.Instance.GetAllParentCategories(); model.Name = category.Name; model.Description = category.Description; return(PartialView(model)); } catch { return(RedirectToAction("Index")); } }
public ActionResult Create(CategoryCRUDViewModel model) { try { if (ModelState.IsValid) { var newCategory = new Category(); newCategory.Name = model.Name; newCategory.ParentCategoryID = model.ParentCategoryID; newCategory.Description = model.Description; CategoriesService.Instance.SaveCategory(newCategory); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } catch { return(RedirectToAction("Index")); } }