Created
January 30, 2019 18:47
-
-
Save evgomes/3589885761850a15bc88568f12fcdd27 to your computer and use it in GitHub Desktop.
PutAsync method from CategoriesController, of Supermarket API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPut("{id}")] | |
public async Task<IActionResult> PutAsync(int id, [FromBody] SaveCategoryResource resource) | |
{ | |
if (!ModelState.IsValid) | |
return BadRequest(ModelState.GetErrorMessages()); | |
var category = _mapper.Map<SaveCategoryResource, Category>(resource); | |
var result = await _categoryService.UpdateAsync(id, 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