I would make asyn an insert of order and relative orderItems that take
some times...
The code is raw sql command of EF core
public IActionResult Create([FromBody] CreateOrderModel model)
{
var lastId = _ctx.Riorcl.Select(x => x.Id).DefaultIfEmpty().Max();
int rowsRiorcAdded;
using (_ctx)
{
AddOrdcli(model);
rowsRiorcAdded = AddRiorcl(model, lastId);
}
return Ok(rowsRiorcAdded);
}
private int AddRiorcl(CreateOrderModel model, int lastId)
{
int rows = 0;
foreach (var item in model.OrderItems)
{
var addRiorcl = "INSERT INTO OrderItems (Id, ...) " +
" VALUES ( @Id... )";
var Id = new SqliteParameter("@Id", lastId++);
...
_ctx.Database.ExecuteSqlCommand(addRiorcl, Id,...);
rows++;
}
return rows;
}
private void AddOrdcli(CreateOrderModel model)
{
var addOrdcli = " INSERT INTO Order ( Id,...) " +
" VALUES (@Id, ... ) ";
v...
_ctx.Database.ExecuteSqlCommand(addOrdcli,...);
}