Example #1
0
        public void AddClaimedProductKey(ClaimedProductKey key)
        {
            if (ClaimedProductKeys == null)
            {
                ClaimedProductKeys = new HashSet <ClaimedProductKey>();
            }

            ClaimedProductKeys.Add(key);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        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;
        }
Example #5
0
        /// <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);
        }
Example #6
0
        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;
        }
Example #7
0
        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;
        }
Example #9
0
        public void AddClaimedProductKey(ClaimedProductKey key)
        {
            if (ClaimedProductKeys == null)
            {
                ClaimedProductKeys = new HashSet<ClaimedProductKey>();
            }

            ClaimedProductKeys.Add(key);
        }
Example #10
0
        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();
        }
Example #11
0
        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();
        }
Example #12
0
 public void InsertClaimedProductKey(ClaimedProductKey claimedProductKey)
 {
     context.ClaimedProductKeys.Add(claimedProductKey);
 }
Example #13
0
        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();
        }
Example #14
0
        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;
            }
        }
Example #15
0
 public void AddClaimedProductKey(ClaimedProductKey claimedKey)
 {
     claimedKey.Listing = this;
     ClaimedProductKeys.Add(claimedKey);
 }
Example #16
0
        public ClaimedProductKey RemoveClaimedProductKey(ClaimedProductKey claimedKey)
        {
            if (ClaimedProductKeys.Contains(claimedKey))
            {
                ClaimedProductKeys.Remove(claimedKey);
                return claimedKey;
            }

            return null;
        }
Example #17
0
        public void CreateClaimedProductKey(ClaimedProductKey key)
        { 
            if (key.ListingID != 0)
            {
                key.Listing = listingRepository.GetListingByID(key.ListingID);
            }
            
            key.Date = DateTime.Now;

            userRepository.InsertClaimedProductKey(key);
            unitOfWork.Save();
        }