private async Task<int> BuildDonationModel(OrderViewModel order, IList<WishlistItem> wishlistItems) { var donation = new Donation { DonorId = order.DonorId, OrderId = order.OrderId, Date = DateTime.Now, Subtotal = order.Subtotal, SalesTax = order.SalesTax, Total = order.Total }; _db.Donations.Add(donation); var donatedItems = order.Items.Join(wishlistItems, oi => oi.WishlistItemId, wi => wi.Id, (oi, wi) => new DonatedItem { Donation = donation, Item = wi, PurchasePrice = oi.Price, Title = oi.Title, }); foreach (var di in donatedItems) { _db.DonatedItems.Add(di); } await _db.SaveChangesAsync(); return donation.Id; }
private OrderViewModel BuildOrderModel(int donorId, IList<CartItem> items) { var orderItems = items.Select(ci => new OrderItemViewModel { WishlistItemId = ci.Item.Id, ItemId = ci.Item.ItemId, Price = ci.Price, Title = ci.Title }).ToList(); var subtotal = items.Sum(oi => oi.Price); var shipping = subtotal * (decimal) (0.05 + new Random().NextDouble() * 0.2); var tax = (subtotal + shipping) * 0.05m; var total = subtotal + shipping + tax; var order = new OrderViewModel { DonorId = donorId, OrderId = Guid.NewGuid().ToString(), Subtotal = subtotal, Shipping = shipping, SalesTax = tax, Total = total, Items = orderItems }; return order; }