public ProductOrderEntry(Order order, ShoppingCartEntry cartEntry) { ListingID = cartEntry.ListingID; Listing = cartEntry.Listing; SalePrice = cartEntry.Listing.SaleOrDefaultPrice(); ClaimedProductKeys = new HashSet<ClaimedProductKey>(); OrderID = order.OrderID; this.Order = order; }
public ProductOrderEntry(Order order, ShoppingCartEntry cartEntry, ClaimedProductKey claimedKey) { ListingID = cartEntry.ListingID; Listing = cartEntry.Listing; SalePrice = cartEntry.Listing.SaleOrDefaultPrice(); ClaimedProductKeys = new HashSet<ClaimedProductKey>() { claimedKey }; claimedKey.ProductOrderEntry = this; OrderID = order.OrderID; this.Order = order; //ProductOrderEntryID = claimedKey.ClaimedProductKeyID; }
public async Task<Order> CreateOrder() { AppUser user = await GetCurrentUser(); if (!user.AssertValidOrder()) { return null; } DateTime orderDate = new DateTime(); orderDate = DateTime.Now; Order order = new Order(user, orderDate); userRepository.InsertOrder(order); this.unitOfWork.Save(); ICollection<ShoppingCartEntry> cartEntries = user.ShoppingCartEntries; foreach (ShoppingCartEntry entry in cartEntries) { List<ProductKey> keys = listingRepository.GetProductKeys().Where(k => k.ListingID == entry.ListingID).Take(entry.Quantity).ToList(); int remainingQuantity = entry.Quantity - keys.Count; if (keys.Count > 0 && keys.Count < entry.Quantity && entry.Listing.ChildListings != null) { foreach (ProductKey productKey in keys) { listingRepository.DeleteProductKey(productKey.ProductKeyID); ClaimedProductKey claimedKey = new ClaimedProductKey(productKey, user, orderDate, "Purchase - Order #" + order.OrderID); user.AddClaimedProductKey(claimedKey); userRepository.InsertClaimedProductKey(claimedKey); unitOfWork.Save(); //unitOfWork.Save(); ProductOrderEntry orderEntry = new ProductOrderEntry(order, entry); order.AddProductOrderEntry(orderEntry); userRepository.InsertProductOrderEntry(orderEntry); unitOfWork.Save(); orderEntry.AddClaimedProductKey(claimedKey); } keys = new List<ProductKey>(); foreach (Listing childListing in entry.Listing.ChildListings) { keys.AddRange(listingRepository.GetProductKeys().Where(k => k.ListingID == childListing.ListingID).Take(remainingQuantity)); } } else if (keys.Count < entry.Quantity && entry.Listing.ChildListings != null) { foreach (Listing childListing in entry.Listing.ChildListings) { keys.AddRange(listingRepository.GetProductKeys().Where(k => k.ListingID == childListing.ListingID).Take(entry.Quantity)); } } if (entry.Listing.ChildListings == null || entry.Listing.ChildListings.Count == 0 || keys.Count == entry.Quantity) { foreach (ProductKey productKey in keys) { listingRepository.DeleteProductKey(productKey.ProductKeyID); ClaimedProductKey claimedKey = new ClaimedProductKey(productKey, user, orderDate, "Purchase - Order #" + order.OrderID); user.AddClaimedProductKey(claimedKey); userRepository.InsertClaimedProductKey(claimedKey); unitOfWork.Save(); ProductOrderEntry orderEntry = new ProductOrderEntry(order, entry); userRepository.InsertProductOrderEntry(orderEntry); unitOfWork.Save(); orderEntry.AddClaimedProductKey(claimedKey); order.AddProductOrderEntry(orderEntry); } } else { for (int i = 0; i < remainingQuantity; i++) { ProductOrderEntry orderEntry = new ProductOrderEntry(order, entry); order.AddProductOrderEntry(orderEntry); userRepository.InsertProductOrderEntry(orderEntry); unitOfWork.Save(); foreach (Listing childListing in entry.Listing.ChildListings) { ProductKey productKey = keys.Where(k => k.Listing.ListingID == childListing.ListingID).First(); keys.Remove(productKey); listingRepository.DeleteProductKey(productKey.ProductKeyID); ClaimedProductKey claimedKey = new ClaimedProductKey(productKey, user, orderDate, "Purchase - Order #" + order.OrderID); userRepository.InsertClaimedProductKey(claimedKey); unitOfWork.Save(); orderEntry.AddClaimedProductKey(claimedKey); user.AddClaimedProductKey(claimedKey); } order.AddProductOrderEntry(orderEntry); } } Listing listing = listingRepository.GetListingByID(entry.ListingID); listing.Quantity -= entry.Quantity; listing.UpdateParentQuantities(); listingRepository.UpdateListing(listing); unitOfWork.Save(); } await DeleteShoppingCart(); BalanceEntry balanceEntry = new BalanceEntry(user, "Purchase - Order #" + order.OrderID, 0 - order.TotalSalePrice() , orderDate); user.BalanceEntries.Add(balanceEntry); //userRepository.InsertBalanceEntry(balanceEntry); user.Balance -= order.TotalSalePrice(); user.AddOrder(order); await userRepository.UpdateAppUser(user); this.unitOfWork.Save(); return userRepository.GetOrderByID(order.OrderID); }
public void AddOrder(Order order) { if (Orders == null) { Orders = new HashSet<Order>(); } Orders.Add(order); }
public ActivityFeedContainer(Order order) : this() { ItemDate = order.SaleDate ?? siteEpoch; Order = order; }
public void EditOrder(Order order) { Order updatedOrder = userRepository.GetOrderByID(order.OrderID); updatedOrder.SaleDate = order.SaleDate; userRepository.UpdateOrder(updatedOrder); unitOfWork.Save(); }
public async Task CreateOrder(Order order, bool alreadyCharged, bool useDBKey = false) { // New orders should only have one product order entry ProductOrderEntry entry = order.ProductOrderEntries.FirstOrDefault(); if (entry.ListingID != 0) { entry.Listing = listingRepository.GetListingByID(entry.ListingID); } DateTime date = DateTime.Now; order.SaleDate = date; String note = "Admin-created order"; ClaimedProductKey newKey = new ClaimedProductKey(); int priceToCharge = 0; if (order.ProductOrderEntries.Count() > 0) { priceToCharge = order.ProductOrderEntries.First().SalePrice; } if (useDBKey) { ProductKey key = GetProductKey(entry.ListingID); newKey = new ClaimedProductKey(key, order.AppUser, date, note); listingRepository.DeleteProductKey(key.ProductKeyID); unitOfWork.Save(); priceToCharge = newKey.Listing.SaleOrDefaultPrice(); entry.AddClaimedProductKey(newKey);//userRepository.InsertClaimedProductKey(newKey); } if (alreadyCharged == false) { BalanceEntry balanceEntry = new BalanceEntry(); balanceEntry.Date = date; balanceEntry.AppUser = order.AppUser; balanceEntry.Notes = note; balanceEntry.PointsAdjusted = priceToCharge; order.AppUser.Balance -= priceToCharge; //userRepository.UpdateAppUser(order.AppUser); //userRepository.InsertBalanceEntry(balanceEntry); order.AppUser.AddBalanceEntry(balanceEntry); } entry.SalePrice = priceToCharge; order.AppUser.AddOrder(order); //userRepository.InsertOrder(order); await userRepository.UpdateAppUser(order.AppUser); unitOfWork.Save(); }
public void UpdateOrder(Order order) { Order targetOrder = context.Orders.Find(order.OrderID); if (targetOrder != null) { targetOrder.SaleDate = order.SaleDate; targetOrder.UserID = order.UserID; } if (order.ProductOrderEntries != null) { foreach (ProductOrderEntry entry in order.ProductOrderEntries) { if (entry.ProductOrderEntryID == 0) { InsertProductOrderEntry(entry); } else { UpdateProductOrderEntry(entry); } } } }
public void InsertOrder(Order order) { context.Orders.Add(order); if (order.ProductOrderEntries != null) { foreach (ProductOrderEntry entry in order.ProductOrderEntries) { if (entry.ProductOrderEntryID == 0) { InsertProductOrderEntry(entry); } else { UpdateProductOrderEntry(entry); } } } }