public void AddClaimedProductKey(ClaimedProductKey key) { if (ClaimedProductKeys == null) { ClaimedProductKeys = new HashSet <ClaimedProductKey>(); } ClaimedProductKeys.Add(key); }
/// <summary> Adds the specified claimed product key entity to this listing. </summary> /// <param name="claimedKey"> The specified claimed product key entity to add to this listing. </param> public void AddClaimedProductKey(ClaimedProductKey claimedKey) { if (ClaimedProductKeys == null) { ClaimedProductKeys = new HashSet <ClaimedProductKey>(); } claimedKey.Listing = this; ClaimedProductKeys.Add(claimedKey); }
public void AddClaimedProductKey(ClaimedProductKey key) { if (ClaimedProductKeys == null) { ClaimedProductKeys = new HashSet <ClaimedProductKey>(); } ClaimedProductKeys.Add(key); key.ProductOrderEntry = this; }
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; }
/// <summary> Removes the specified claimed product key entity from this listing. </summary> /// <param name="claimedKey"> The specified claimed product key entity to remove from this listing. </param> /// <returns> Returns the removed claimed product key entity if it existed, otherwise returns null. </returns> public ClaimedProductKey RemoveClaimedProductKey(ClaimedProductKey claimedKey) { if (this?.ClaimedProductKeys?.Count == 0) { return(null); } if (ClaimedProductKeys.Contains(claimedKey)) { ClaimedProductKeys.Remove(claimedKey); return(claimedKey); } return(null); }
public ProductOrderEntry(Order order, ClaimedProductKey claimedKey) { ListingID = claimedKey.ListingID; Listing = claimedKey.Listing; SalePrice = claimedKey.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 AddClaimedProductKey(ClaimedProductKey key) { if (ClaimedProductKeys == null) { ClaimedProductKeys = new HashSet<ClaimedProductKey>(); } ClaimedProductKeys.Add(key); key.ProductOrderEntry = this; }
public void AddClaimedProductKey(ClaimedProductKey key) { if (ClaimedProductKeys == null) { ClaimedProductKeys = new HashSet<ClaimedProductKey>(); } ClaimedProductKeys.Add(key); }
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 EditClaimedProductKey(ClaimedProductKey key) { ClaimedProductKey updatedKey = userRepository.GetClaimedProductKeyByID(key.ClaimedProductKeyID); updatedKey.AcquisitionTitle = key.AcquisitionTitle; updatedKey.ListingID = key.ListingID; updatedKey.IsGift = key.IsGift; updatedKey.Key = key.Key; userRepository.UpdateClaimedProductKey(updatedKey); unitOfWork.Save(); }
public void InsertClaimedProductKey(ClaimedProductKey claimedProductKey) { context.ClaimedProductKeys.Add(claimedProductKey); }
public void CreateClaimedProductKey(ClaimedProductKey key, string nickname) { if (key.ListingID != 0) { key.Listing = listingRepository.GetListingByID(key.ListingID); } if (String.IsNullOrEmpty(nickname) == false) { key.AppUser = userRepository.GetAppUsers().Where(a => object.Equals(nickname.ToUpper(), a.UserName.ToUpper())).SingleOrDefault(); } if (key.AppUser == null) { return; } key.Date = DateTime.Now; userRepository.InsertClaimedProductKey(key); unitOfWork.Save(); }
public void UpdateClaimedProductKey(ClaimedProductKey claimedProductKey) { ClaimedProductKey targetClaimedProductKey = context.ClaimedProductKeys.Find(claimedProductKey.ClaimedProductKeyID); if (targetClaimedProductKey != null) { targetClaimedProductKey.AcquisitionTitle = claimedProductKey.AcquisitionTitle; targetClaimedProductKey.Date = claimedProductKey.Date; targetClaimedProductKey.IsRevealed = claimedProductKey.IsRevealed; targetClaimedProductKey.IsUsed = claimedProductKey.IsUsed; targetClaimedProductKey.Key = claimedProductKey.Key; targetClaimedProductKey.ListingID = claimedProductKey.ListingID; targetClaimedProductKey.UserID = claimedProductKey.UserID; targetClaimedProductKey.IsGift = claimedProductKey.IsGift; } }
public void AddClaimedProductKey(ClaimedProductKey claimedKey) { claimedKey.Listing = this; ClaimedProductKeys.Add(claimedKey); }
public ClaimedProductKey RemoveClaimedProductKey(ClaimedProductKey claimedKey) { if (ClaimedProductKeys.Contains(claimedKey)) { ClaimedProductKeys.Remove(claimedKey); return claimedKey; } return null; }
public void CreateClaimedProductKey(ClaimedProductKey key) { if (key.ListingID != 0) { key.Listing = listingRepository.GetListingByID(key.ListingID); } key.Date = DateTime.Now; userRepository.InsertClaimedProductKey(key); unitOfWork.Save(); }