public async Task <IActionResult> CreateCategory(CategoryRegisterDTO categoryRegisterDTO) { var category = _mapper.Map <Category>(categoryRegisterDTO); _repo.Add(category); if (await _repo.SaveAll()) { var categoryToReturn = _mapper.Map <CategoryReturnDTO>(category); return(CreatedAtRoute("GetCategory", new { id = category.CategoryId }, categoryToReturn)); } throw new Exception("حدث مشكلة في حفظ القسم الجديده"); }
public async Task <IActionResult> InsertCategoryAsync([FromBody] CategoryRegisterDTO dTO) { await _categoryService.RegisterAsync(dTO); if (dTO.Id != 0) { return(SuccessMessageHandler.EditCategory()); } else { return(SuccessMessageHandler.InsertCategory()); } }
public async Task RegisterAsync(CategoryRegisterDTO dTO) { var category = new Category(); _mapper.Map(dTO, category); if (dTO.Id == null) { await _repositoryCategory.InsertAsync(category); } else { await _repositoryCategory.UpdateAsync(category); } }