public static SaleModel From(Sale value) { return new SaleModel { Id = value.Id, CompanyName = value.Company.Name, Date = value.Date.ToString(Constants.DATE_FORMAT), Value = value.Items.Select(it => it.Quantity * it.Price).Sum().Formatted(), Items = value.Items.Select(SaleItemModel.From).ToList(), }; }
/// <summary> /// Fixes the ProductId on the items (this is done by SaveChanges in normal execution) /// </summary> private static void FixItems(Sale sale) { foreach (var item in sale.Items) item.ProductId = item.Product.Id; }