public async Task <CatalogsResponse> ExecuteAsync(Guid typefoodId, UpdateCatalogsRequest request) { Catalog foundCatalogs = await _context.Catalogs.FirstOrDefaultAsync(t => t.Id == typefoodId); if (foundCatalogs != null) { Catalog mappedCatalogs = _mapper.Map <UpdateCatalogsRequest, Catalog>(request); mappedCatalogs.Id = typefoodId; _context.Entry(foundCatalogs).CurrentValues.SetValues(mappedCatalogs); await _context.SaveChangesAsync(); } return(_mapper.Map <Catalog, CatalogsResponse>(foundCatalogs)); }
public async Task <IActionResult> UpdateCatalogs(Guid catalogofcatalogsId, UpdateCatalogsRequest catalogofcatalogs, [FromServices] IUpdateCatalogsCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { CatalogsResponse response = await command.ExecuteAsync(catalogofcatalogsId, catalogofcatalogs); return(CreatedAtRoute("GetSingleCatalogs", new { catalogofcatalogsId = response.Id }, response)); } catch (CannotCreateCatalogsExeption exception) { foreach (var error in exception.Errors) { ModelState.AddModelError(exception.Message, error.Description); } return(BadRequest(ModelState)); } }