public ActionResult Create(SubcategoryAdminViewModel model) { if (!ModelState.IsValid) { return(View("Edit", model)); } _subcategoryRepository.Create(Mapper.Map <Subcategory>(model)); return(RedirectToAction("Index")); }
public ActionResult Create(SubcategoryAdminViewModel model) { if (!ModelState.IsValid) { return View("Edit", model); } _subcategoryRepository.Create(_mapper.Map<Subcategory>(model)); _unitOfWork.SaveChanges(); return RedirectToAction("Index"); }
public void SaveSubcategory(Subcategory subcategory) { if (subcategory.Id == 0) { subcategoryRepository.Create(subcategory); } else { subcategoryRepository.Update(subcategory.Id, subcategory); } subcategoryRepository.SaveChanges(); }
public async Task <IActionResult> Create(SubCategoryDto subCategoryDto) { if (await _repo.SubCategoryNameExists(subCategoryDto.Name.ToLower(), subCategoryDto.CategoryId)) { return(BadRequest("SubCategory already exists")); } var subCategoryToCreate = new SubCategory { Name = subCategoryDto.Name, Active = subCategoryDto.Active, CategoryId = subCategoryDto.CategoryId }; if (await _repo.Create(subCategoryToCreate)) { return(Ok(subCategoryToCreate)); } return(BadRequest(subCategoryToCreate)); }