Skip to content

Instantly share code, notes, and snippets.

@evgomes
Created January 30, 2019 15:28
Show Gist options
  • Save evgomes/671ad2252b05346b68e0b8d490f70995 to your computer and use it in GitHub Desktop.
Save evgomes/671ad2252b05346b68e0b8d490f70995 to your computer and use it in GitHub Desktop.
Finished PostAsync method of CategoriesController, from Supermarket API
[HttpPost]
public async Task<IActionResult> PostAsync([FromBody] SaveCategoryResource resource)
{
if (!ModelState.IsValid)
return BadRequest(ModelState.GetErrorMessages());
var category = _mapper.Map<SaveCategoryResource, Category>(resource);
var result = await _categoryService.SaveAsync(category);
if (!result.Success)
return BadRequest(result.Message);
var categoryResource = _mapper.Map<Category, CategoryResource>(result.Category);
return Ok(categoryResource);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment