public async Task <CategoryStatusResponse> SaveCategoryAsync(Category category) { try { Category newAddedCategory = await categoryRepository.AddAsync(category); return(new CategoryStatusResponse(newAddedCategory)); } catch (Exception ex) { return(new CategoryStatusResponse(ex.Message)); } }
public async Task <IActionResult> Create([Bind("Id,Name")] Category category) { if (ModelState.IsValid) { await _categoriesRepository.AddAsync(category); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Index([FromBody] CreateGategoryViewModel vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.Select(v => v.Errors))); } var sectionExist = await _sectionsRepository.Contains(vm.SectionId); if (sectionExist) { var category = _mapper.Map <Category>(vm); await _categoriesRepository.AddAsync(category); return(Ok()); } return(BadRequest()); }
public async Task <IActionResult> Add(ProductCategory category) { await categoriesRepository.AddAsync(category); return(RedirectToAction("Index")); }