public async Task <long> Add(NewOrder model, int corpClientId) { var ids = model.OrderItems.Select(i => i.ProductId).ToList(); var prods = await productApp.GetRange(corpClientId, ids); int i = 1; var units = await measureUnitApp.GetAll(); foreach (var item in model.OrderItems) { item.ItemNumber = i; var prod = prods.FirstOrDefault(p => p.ProductId == item.ProductId); item.ProductPrice = prod.Price; var pType = units.FirstOrDefault(u => u.MeasureUnitId == prod.MeasureUnitId).MeasureUnitTypeId; var qType = units.FirstOrDefault(u => u.MeasureUnitId == item.MeasureUnitId).MeasureUnitTypeId; await CalculateItem(item, prod.MeasureUnitId, pType, qType, corpClientId); i++; } return(await orderApp.Add(model, corpClientId)); }