public async Task <ActionResult <CategoryDetailResource> > DeleteCategory(int id) { CategoryResponse response = await _categoryService.DeleteAsync(id); if (!response.Success) { return(BadRequest(response.Message)); } CategoryDetailResource deletedResource = _mapper.Map <CategoryDetailResource>(response.Category); return(Ok(deletedResource)); }
public async Task <ActionResult <CategoryDetailResource> > GetCategory(int id) { CategoryResponse response = await _categoryService.FindByIdAsync(id); if (!response.Success) { return(NotFound(response.Message)); } CategoryDetailResource resource = _mapper.Map <CategoryDetailResource>(response.Category); return(Ok(resource)); }
public async Task <ActionResult <CategoryDetailResource> > PutCategory(int id, CategorySaveResource resource) { Category category = _mapper.Map <Category>(resource); CategoryResponse response = await _categoryService.UpdateAsync(id, category); if (!response.Success) { return(BadRequest(response.Message)); } CategoryDetailResource updatedResource = _mapper.Map <CategoryDetailResource>(response.Category); return(Ok(updatedResource)); }
public async Task <ActionResult <CategoryDetailResource> > PostCategory(CategorySaveResource resource) { Category category = _mapper.Map <Category>(resource); CategoryResponse response = await _categoryService.SaveAsync(category); if (!response.Success) { return(BadRequest(response.Message)); } CategoryDetailResource savedResource = _mapper.Map <CategoryDetailResource>(response.Category); return(CreatedAtAction(nameof(GetCategory), new { id = savedResource.Id }, savedResource)); }