public IActionResult CreateCategory([FromBody] CategoryForCreateDto categoryDto) { var categoryEntity = mapper.Map <Category>(categoryDto); categoryService.Save(categoryEntity); try { context.SaveChanges(); var outputDto = mapper.Map <CategoryForCreateDto>(categoryEntity); return(Ok(new DtoOutput <CategoryForCreateDto>(outputDto))); } catch (Exception ex) { string message = ex.InnerException.Message; return(BadRequest(new DtoOutput <CategoryDto>(null, message, ErrorCode.CATEGORY_CREATE_FAILED))); } }
public IActionResult EditCategory(int id, [FromBody] CategoryForCreateDto category) { category.Id = id; var categoryEntity = mapper.Map <Category>(category); categoryService.Save(categoryEntity); try { context.SaveChanges(); var outputDto = mapper.Map <CategoryDto>(categoryEntity); return(Ok(new DtoOutput <CategoryDto>(outputDto, "Building edited successfully", 0))); } catch (Exception) { return(BadRequest(new DtoOutput <CategoryForCreateDto>(category, "Unable to edit Category", ErrorCode.CATEGORY_EDIT_FAILED))); } }