private async Task <OrderEntity> TransposeCartToOrder(IList <CartItemViewModel> cart) { await ValidateCart(cart); var productIds = cart.Select(ci => ci.Product.Id); var products = (await ProductsRepo.FindAll(p => productIds.Any(id => id == p.Id))).ToList(); var ops = (from cartItem in cart let product = products.First(p => p.Id == cartItem.Product.Id) select new OrderProductEntity { Product = product, UnitPrice = product.Price, Unit = product.Unit, Quantity = cartItem.Quantity }) .ToList(); return(new OrderEntity { Buyer = CurrentBuyerProfile, TotalPrice = ops.Sum(op => op.Quantity * op.UnitPrice), Products = ops }); }