public ActionResult AddCategory(CategoryModel category) { CategoryInfo categoryInfo = category.GetEntity(); if (ValidationCategoryIsExist(categoryInfo)) { category.CategoryList = DropDownListHelper.GetAllCategorySelectList(); category.StateMessage = "The same category has already been exist."; category.ErrorState = true; return View(category); } else { this.ICategoryInfoDataProvider.Add(categoryInfo); return RedirectToAction("Index"); } }
public static CategoryModel GetViewModel(CategoryInfo category) { CategoryModel model = new CategoryModel(); model.ID = category.ID; model.CategoryName = category.CategoryName; model.ParentCategoryName = DropDownListHelper.GetParentCategoryName(category); ICategoryInfoDataProvider dataProvider = new CategoryInfoDataProvider(); if (category.BookAndCategorys.Count > 0 ||dataProvider.GetCategoryListByParentID(category.ID).Count() > 0 ) { model.IsUse = true; } return model; }
public ActionResult EditCategory(long id) { CategoryModel category = new CategoryModel(); CategoryInfo categoryInfo = this.ICategoryInfoDataProvider.GetCategoryByID(id); category = CategoryModel.GetViewModel(categoryInfo); if (categoryInfo.ParentCategoryInfo != null) { category.CategorySelectedID = categoryInfo.ParentCategoryInfo.ID; category.CategoryList = DropDownListHelper.GetCategorySelectListBySelectedID(categoryInfo.ParentCategoryInfo.ID, categoryInfo.ID); } else { category.CategoryList = DropDownListHelper.GetAllCategorySelectList(categoryInfo.ID); } return View(category); }
public ActionResult EditCategory(CategoryModel category) { if (category != null && !DropDownListHelper.ValidateCategory(category.ID, category.CategorySelectedID)) { CategoryInfo categoryInfo = category.GetEntity(); if (ValidationCategoryIsExist(categoryInfo)) { category.CategoryList = DropDownListHelper.GetCategorySelectListBySelectedID(category.CategorySelectedID, category.ID); category.StateMessage = "The same category has already been exist."; category.ErrorState = true; return View(category); } else { this.ICategoryInfoDataProvider.Update(categoryInfo); return RedirectToAction("Index"); } } else { category.CategoryList = DropDownListHelper.GetCategorySelectListBySelectedID(category.CategorySelectedID, category.ID); category.StateMessage = "The parent category cannot choose a subcategory of itself."; category.ErrorState = true; return View(category); } }
public ActionResult AddCategory() { CategoryModel category = new CategoryModel(); category.CategoryList = DropDownListHelper.GetAllCategorySelectList(); return View(category); }