public async Task <IActionResult> UpdateShipment( [FromRoute] int id, [FromQuery] string partId, [FromQuery] int shipmentQty, [FromQuery] DateTime shipmentDate ) { string sql = "SELECT * FROM shipments WHERE shipment_id = {0}"; string sqlDate = shipmentDate.ToString("yyyy-MM-dd"); var shipment = await _context.Shipments.FindAsync(id); if (shipment == null || shipment.ShipmentQty == shipmentQty) { return(NotFound()); } if (shipment.ShipmentQty > shipmentQty) { var number = shipment.ShipmentQty - shipmentQty; var query1 = await _context.Database.ExecuteSqlInterpolatedAsync($"CALL shipment_update({id}, {partId}, {shipmentQty}, {sqlDate})"); if (query1 == -1) { await _context.Database.ExecuteSqlInterpolatedAsync($"CALL warehouse_after_shipment_update({partId}, {-number})"); _context.Entry(shipment).Reload(); var result1 = await _context.Shipments.FromSqlRaw(sql, id).FirstAsync(); return(Ok(result1)); } else { return(NotFound()); } } var partNumber = shipmentQty - shipment.ShipmentQty; var query2 = await _context.Database.ExecuteSqlInterpolatedAsync($"CALL shipment_update({id}, {partId}, {shipmentQty}, {sqlDate})"); if (query2 != -1) { return(NotFound()); } await _context.Database.ExecuteSqlInterpolatedAsync($"CALL warehouse_after_shipment_update({partId}, {partNumber})"); _context.Entry(shipment).Reload(); var result2 = await _context.Shipments.FromSqlRaw(sql, id).FirstAsync(); return(Ok(result2)); }
public async Task <IActionResult> UpdateFeed( [FromRoute] int id, [FromQuery] string partId, [FromQuery] int partQty ) { string sql = "SELECT * FROM feeds WHERE feed_id = {0}"; var feed = await _context.Feeds.FindAsync(id); if (feed == null || feed.PartQty == partQty) { return(NotFound()); } if (feed.PartQty > partQty) { var number = feed.PartQty - partQty; var query1 = await _context.Database.ExecuteSqlInterpolatedAsync($"CALL feed_update({id}, {partId}, {partQty})"); if (query1 == -1) { await _context.Database.ExecuteSqlInterpolatedAsync($"CALL warehouse_after_feed_update({partId}, {-number})"); _context.Entry(feed).Reload(); var result1 = await _context.Feeds.FromSqlRaw(sql, id).FirstAsync(); return(Ok(result1)); } else { return(NotFound()); } } var partNumber = partQty - feed.PartQty; var query2 = await _context.Database.ExecuteSqlInterpolatedAsync($"CALL feed_update({id}, {partId}, {partQty})"); if (query2 != -1) { return(NotFound()); } await _context.Database.ExecuteSqlInterpolatedAsync($"CALL warehouse_after_feed_update({partId}, {partNumber})"); _context.Entry(feed).Reload(); var result2 = await _context.Feeds.FromSqlRaw(sql, id).FirstAsync(); return(Ok(result2)); }