public ActionResult AddOrEditCategory(EditCategoryViewModel categoryViewModel) { categoryViewModel.Uniqueness = _categoryProvider.IsUnique(categoryViewModel.CategoryId, categoryViewModel.Name); if (categoryViewModel.Uniqueness == UniqueValidation.Dublicate) { ModelState.AddModelError("Name", "This category is already exists"); } if (categoryViewModel.Uniqueness == UniqueValidation.Error) { ModelState.AddModelError("Name", "Name is required"); } Category category = ParseCategory(categoryViewModel); if (ModelState.IsValid) { if (categoryViewModel.CategoryId == 0) { _categoryProvider.InsertCategory(category); } else { _categoryProvider.UpdateCategory(category); } return(RedirectToAction("ShowCategories")); } else { categoryViewModel = ParseCategory(category); return(View("AddOrEditCategory", categoryViewModel)); } }
public async Task <StandardOutput <bool> > UpdateCategory(CreateUpdateCategoryInput input) { var responseMessage = await _categoryProvider.UpdateCategory(input); if (responseMessage.StateCode != Define.StateCode.OK) { return new StandardOutput <bool> { Entity = false, Message = $"Update category failed. Check if category Name: {input.Name} is already existed or id {input.Id} Not Found." } } ; return(new StandardOutput <bool> { Entity = true, Message = "Update category succeed." }); }