public async Task <ActionResult> Update(int id, CategoryDtos categoryDtos) { try { var exist = await this._categoryRepositry.GetOneAsyn(id); if (exist == null) { return(NotFound($"No Category found with this id {id}.")); } var category = _mapper.Map <Category>(categoryDtos); var data = await _categoryRepositry.Update(id, category); if (data == false) { return(BadRequest("This category could not be updated.")); } return(Ok("This category has been updated.")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> Add(CategoryDtos categoryDtos) { try { var category = _mapper.Map <Category>(categoryDtos); var data = await _categoryRepositry.Add(category); if (data == null) { return(BadRequest("This category could not be added.")); } return(Ok($"the {data.Name} category has been created.")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }