public async Task <IActionResult> PutStockItemAsync(int id, [FromBody] PutStockItemsRequest request) { Logger?.LogDebug("'{0}' has been invoked", nameof(PutStockItemAsync)); var response = new Response(); try { // Get stock item by id var entity = await DbContext.GetStockItemsAsync(new StockItem(id)); // Validate if entity exists if (entity == null) { return(NotFound()); } // Set changes to entity entity.StockItemName = request.StockItemName; entity.SupplierID = request.SupplierID; entity.ColorID = request.ColorID; entity.UnitPrice = request.UnitPrice; // Update entity in repository DbContext.Update(entity); // Save entity in database await DbContext.SaveChangesAsync(); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "There was an internal error,please contact to technical support."; Logger?.LogCritical("There was an error on '{0}'", nameof(PutStockItemAsync), ex); } return(response.ToHttpResponse()); }
public async Task <IActionResult> PutStockItemAsync(int id, [FromBody] PutStockItemsRequest request) { Logger?.LogDebug("'{0}' foi chamada", nameof(PutStockItemAsync)); var response = new Response(); try { // Get do produto pelo id var entity = await _context.GetStockItemsByStockItemNameAsync(new StockItem(id)); // Valida existente if (entity == null) { return(NotFound()); } // Set do update entity.StockItemName = request.StockItemName; entity.FornecedorID = request.FornecedorID; entity.ColorID = request.ColorID; entity.PrecoUnidade = request.PrecoUnidade; // Update e save no BD _context.Update(entity); await _context.SaveChangesAsync(); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "Houve um erro interno, por favor contate o suporte."; Logger?.LogCritical("Houve um erro na chamada '{0}' invocando: {1} ", nameof(PutStockItemAsync), ex); } return(response.ToHttpResponse()); }