Example #1
0
 public override void AdjustStock(StockQuantity quantity)
 {
     if (quantity is DiscreteStockQuantity)
     {
         DiscreteStockQuantity quan = quantity as DiscreteStockQuantity;
         _StoredStock += quan.Quantity;
     }
 }
Example #2
0
 public override void AdjustStock(StockQuantity quantity)
 {
     if (quantity is PrePackedStockQuantity)
     {
         PrePackedStockQuantity quan = quantity as PrePackedStockQuantity;
         _StoredStock += quan.Quantity;
     }
 }
Example #3
0
 public override void AdjustStock(StockQuantity quantity)
 {
     if (quantity is VolumeStockQuantity)
     {
         VolumeStockQuantity quan = quantity as VolumeStockQuantity;
         _StoredStock += quan.Quantity;
         return;
     }
 }
Example #4
0
 public ProductsQueryBuilder FilterByStockQuantity(StockQuantity stockQuantity)
 {
     if (stockQuantity != null)
     {
         _query = _query
                  .Where(x => x.StockQuantity >= stockQuantity.QuantityFrom)
                  .Where(x => x.StockQuantity <= stockQuantity.QuantityTo);
     }
     return(this);
 }
Example #5
0
        public override bool Purchase(StockQuantity quantity, out Item item)
        {
            PrePackedStockQuantity quan = quantity as PrePackedStockQuantity;
            double targetQuantity       = 1;

            if (quantity != null)
            {
                if (quan.Quantity > _ShelfStock)
                {
                    targetQuantity = _ShelfStock;
                }
                else if (_ShelfStock >= quan.Quantity)
                {
                    targetQuantity = quan.Quantity;
                }
            }
            else if (quantity == null)
            {
                if (_ShelfStock > 0)
                {
                    targetQuantity = 1;
                }
                if (_ShelfStock <= 0)
                {
                    targetQuantity = 0;
                }
            }

            // Calculations
            _ShelfStock -= targetQuantity;
            // ^^^^^

            if (targetQuantity == 0)
            {
                item = null;
                return(false);
            }
            else
            {
                item = new Item((Convert.ToInt32(targetQuantity)), (Line.Description), (targetQuantity * calculateweight));
            }
            return(true);
        }
Example #6
0
        public void OrderVerifiedAlreadyReadyDoesNotRaiseEvent()
        {
            var product      = new OrderProduct(productId: 123, quantity: 1);
            var domainEvents = new SpyDomainEvents();
            var order        = new Order(orderId: 234, products: new[] { product })
            {
                DomainEvents =
                {
                    Instance = domainEvents,
                }
            };

            order.Verify();
            domainEvents.Clear();

            order.Verify();

            domainEvents.RaisedEvents.Should().BeEmpty();

            StockQuantity quantity    = new StockQuantity(123);
            int           intQuantity = quantity;
        }
Example #7
0
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = Attributes != null?Attributes.GetHashCode() : 0;

                hashCode = (hashCode * 397) ^ (CatalogVisibility != null ? CatalogVisibility.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Categories != null ? Categories.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Description != null ? Description.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ExternalUrl != null ? ExternalUrl.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ Featured.GetHashCode();
                hashCode = (hashCode * 397) ^ Id;
                hashCode = (hashCode * 397) ^ (Images != null ? Images.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ InStock.GetHashCode();
                hashCode = (hashCode * 397) ^ ManageStock.GetHashCode();
                hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ OnSale.GetHashCode();
                hashCode = (hashCode * 397) ^ ParentId;
                hashCode = (hashCode * 397) ^ (Permalink != null ? Permalink.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Price != null ? Price.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (PriceHtml != null ? PriceHtml.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ Purchasable.GetHashCode();
                hashCode = (hashCode * 397) ^ (RegularPrice != null ? RegularPrice.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (RelatedIds != null ? RelatedIds.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (SalePrice != null ? SalePrice.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ShortDescription != null ? ShortDescription.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Sku != null ? Sku.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Slug != null ? Slug.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Status != null ? Status.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (StockQuantity != null ? StockQuantity.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Tags != null ? Tags.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (TaxClass != null ? TaxClass.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (TaxStatus != null ? TaxStatus.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ TotalSales;
                hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ Virtual.GetHashCode();
                return(hashCode);
            }
        }
Example #8
0
        public override bool Purchase(StockQuantity quantity, out Item item)
        {
            VolumeStockQuantity quan = quantity as VolumeStockQuantity;
            double targetQuantity    = 1;

            if (quantity != null)
            {
                if (quan.Quantity > _ShelfStock)
                {
                    targetQuantity = _ShelfStock;
                }
                else if (_ShelfStock >= quan.Quantity)
                {
                    targetQuantity = quan.Quantity;
                }
            }
            else if (quantity == null)
            {
                if (_ShelfStock > 0)
                {
                    targetQuantity = _DefaultPurchase;
                }
                else if (_ShelfStock - _DefaultPurchase <= 0)
                {
                    targetQuantity = 0;
                }
                else if (_ShelfStock - quan.Quantity <= 0)
                {
                    targetQuantity = 0;
                }
            }

            // Calculations
            _ShelfStock -= targetQuantity;

            if (targetQuantity == 0)
            {
                item = null;
                return(false);
            }
            else
            {
                item = new Item((1), (Line.Description + " " + targetQuantity + " kg"), (targetQuantity));
            }
            return(true);

            /// old code - using for reference in the future - please ignore

            /* bool QuantityIsVolume = false;
             * VolumeStockQuantity quan = quantity as VolumeStockQuantity;
             * if (quantity is VolumeStockQuantity)
             *  {
             *      QuantityIsVolume = true;
             *  }
             * else if (quantity is DiscreteStockQuantity || quantity == null)
             * {
             *      QuantityIsVolume = false;
             *  }
             *
             *  if (QuantityIsVolume == true)
             *  {
             *          if (quan.Quantity > _ShelfStock)
             *          {
             *              double maxshelf = _ShelfStock;
             *              _ShelfStock -= maxshelf;
             *          }
             *          else if (_ShelfStock >= quan.Quantity)
             *          {
             *              _ShelfStock -= quan.Quantity;
             *          }
             *   }
             * else if (QuantityIsVolume == false)
             * {
             *          if (_ShelfStock > _DefaultPurchase)
             *          {
             *              _ShelfStock -= _DefaultPurchase;
             *          }
             * }
             *
             *  if (quantity == null)
             *  {
             *
             *      item = null;
             *      return false;
             *  }
             *  else
             *      item = new Item((1), (Line.Description + " " + quan.Quantity + " kg"), (quan.Quantity));
             *      return true; */
        }
Example #9
0
        public override bool Purchase(StockQuantity quantity, out Item item)
        {
            DiscreteStockQuantity quan = quantity as DiscreteStockQuantity;
            int targetQuantity         = 1;

            if (quantity != null)
            {
                if (quan.Quantity > _ShelfStock)
                {
                    targetQuantity = _ShelfStock;
                }
                else if (_ShelfStock >= quan.Quantity)
                {
                    targetQuantity = quan.Quantity;
                }
            }
            else if (quantity == null)
            {
                if (_ShelfStock > 0)
                {
                    targetQuantity = 1;
                }
                if (_ShelfStock <= 0)
                {
                    targetQuantity = 0;
                }
            }

            // Calculations
            _ShelfStock -= targetQuantity;
            // ^^^^^

            if (targetQuantity == 0)
            {
                item = null;
                return(false);
            }
            else
            {
                item = new Item((targetQuantity), Line.Description, (targetQuantity * WeightPerItem));
            }
            return(true);

            // OLD CODE THAT DIDN'T WORK - KEEPING IT FOR REFERENCE //

            /* if (quantity is DiscreteStockQuantity)
             *   {
             *       QuantityIsDiscrete = true;
             *   }
             *   else if (quantity is VolumeStockQuantity || quantity == null)
             *   {
             *       QuantityIsDiscrete = false;
             *   }
             *
             *
             *   if (QuantityIsDiscrete == true)
             *   {
             *        if (quan.Quantity > _ShelfStock)
             *        {
             *           int maxshelf = quan.Quantity;
             *           _ShelfStock -= maxshelf;
             *        }
             *        else if (_ShelfStock >= quan.Quantity)
             *        {
             *           _ShelfStock -= quan.Quantity;
             *        }
             *    }
             *   else if (QuantityIsDiscrete == false)
             *   {
             *           if (_ShelfStock > 0)
             *           {
             *               _ShelfStock -= 1;
             *           }
             *
             * }
             * if(quantity == null)
             * {
             *   item = null;
             *   return false;
             * }
             * else
             * item = new Item((quan.Quantity), Line.Description, (quan.Quantity * WeightPerItem));
             * return true; */
        }
Example #10
0
 public bool Purchase(StockQuantity quantity, out Item items)
 {
     return(_Stock.Purchase(quantity, out items));
 }
Example #11
0
 public abstract bool Purchase(StockQuantity quantity, out Item item);
Example #12
0
 public abstract void AdjustStock(StockQuantity quantity);
Example #13
0
        /// <summary>
        /// Performs operations on the selected portfolio as per user desire
        /// </summary>
        /// <param name="portfolioName">The portfolio to operate on</param>
        private static void PortfolioOperations(string portfolioName)
        {
            if (portfolioName == "X")
            {
                return;
            }
            if (account.PortfolioCount < 1)
            {
                Console.WriteLine("Portfolio not found");
                return;
            }
            Portfolio selected = account.findPortfolio(portfolioName);

            if (selected == null)
            {
                Console.WriteLine("Portfolio not found");
                return;
            }


            while (true)//Loop until user returns (chooses X in the menu)
            {
                float positions = selected.PositionsBalance;
                float gl        = selected.GainLossPercent;
                float glv       = selected.PositionsBalance;//selected.GainLossValue;

                string updown = "+";
                if (glv < 0)
                {
                    updown = "";
                }
                Console.WriteLine("\nPositions Balance: $" + positions + "\nGains/Losses: " + updown + "$" + glv + " (" + updown + gl + "%)" + "\nWhat would you like to do?\nB - Buy stocks\nS - Sell stocks\nV - View report\nSP - Sell this entire portfolio\nX - Return to main menu");
                string input = Console.ReadLine().ToUpper().Trim();
                Console.WriteLine();
                if (input == "B")//Buy a stock
                {
                    string selection     = "";
                    Stock  selectedStock = null;
                    bool   loop          = true;
                    while (loop)
                    {
                        Console.Write("Enter the name or the ticker of the stock to be purchased(To see a list of buyable stocks, enter 'STOCKLIST'), or enter X to cancel: ");
                        selection = Console.ReadLine();
                        Console.WriteLine();
                        if (selection == "X" || selection == "x")
                        {
                            loop = false; break;
                        }
                        if (selection == "STOCKLIST")//If the user wants to see available stocks and prices
                        {
                            foreach (Stock s in stocks)
                            {
                                Console.WriteLine(s.ToString());
                            }
                        }
                        else
                        {
                            foreach (Stock s in stocks)//search through stocks for selected stock
                            {
                                if (selection == s.Name || selection == s.Ticker || selection == s.Ticker.ToLower())
                                {
                                    selectedStock = s;
                                    loop          = false;
                                    break;
                                }
                            }
                            if (selectedStock == null)//if stock was not found, indicate to the user to try again
                            {
                                Console.WriteLine("Stock not found, please try again");
                            }
                        }
                    }
                    if (selection == "X" || selection == "x")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine(selectedStock.ToString());
                        Console.WriteLine("Available balance: " + account.CashBalance);
                        if (input != "X" && input != "x")
                        {
                            loop = true;
                        }
                        int quant = 0;
                        while (loop)
                        {
                            Console.Write("Enter the quantity to be purchased, or enter the dollar amount of stocks to purchase (Ex: $35.10)\n(A flat rate fee of $9.99 will be applied) or enter X to cancel: ");
                            string read = Console.ReadLine();
                            if (read == "X" || read == "x")
                            {
                                break;
                            }
                            if (read[0] == '$')
                            {
                                try
                                {
                                    string substring = read.Substring(1);
                                    float  dollars   = Convert.ToSingle(substring);
                                    quant = (int)(dollars / selectedStock.StockPrice);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Error, invalid input");
                                }
                            }
                            else
                            {
                                try
                                {
                                    quant = Convert.ToInt32(read);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Error, invalid input");
                                }
                            }
                            int code = account.Buy(selected.Name, selectedStock.Name, quant);
                            if (code == 0)
                            {
                                loop = false;
                            }
                        }
                    }
                }
                else if (input == "S")
                {
                    StockQuantity selectedStock = null;
                    bool          loop          = true;
                    while (loop)
                    {
                        Console.Write("Please enter the ticker or name of the stock to be sold, or enter STOCKLIST to see available stocks or prest X to cancel: ");
                        string selection = Console.ReadLine();
                        if (selection == "X" || selection == "x")
                        {
                            break;
                        }
                        if (selection == "STOCKLIST")//If the user wants to see available stocks and prices
                        {
                            foreach (StockQuantity s in selected.Stocks)
                            {
                                Console.WriteLine(s.ToString());
                            }
                        }
                        else
                        {
                            foreach (StockQuantity s in selected.Stocks)//search through stocks for selected stock
                            {
                                if (selection == s.Stock.Name || selection == s.Stock.Ticker)
                                {
                                    selectedStock = s;
                                    loop          = false;
                                    break;
                                }
                            }
                            if (selectedStock == null)//if stock was not found, indicate to the user to try again
                            {
                                Console.WriteLine("You don't own any stock of that type");
                            }
                        }
                    }
                    loop = true;
                    int quant = 0;
                    while (loop)
                    {
                        Console.Write(selectedStock.ToString() + "\nPlease enter the quantity to sell, or enter X to cancel: ");
                        string read = Console.ReadLine();
                        if (read == "X")
                        {
                            loop = false;
                        }
                        else
                        {
                            try
                            {
                                quant = Convert.ToInt32(read);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Invalid input, please use integer input only");
                            }
                            if (quant > selectedStock.Quantity)
                            {
                                Console.WriteLine("You do not own that many shares");
                            }
                            else
                            {
                                account.Sell(selected.Name, selectedStock.Stock.Name, quant);
                                loop = false;
                            }
                        }
                    }
                }
                else if (input == "V")
                {
                    Console.WriteLine(selected.Report());
                }
                else if (input == "X")
                {
                    return;
                }
                else if (input == "SP")
                {
                    for (int i = selected.Stocks.Count - 1; i >= 0; i--)
                    {
                        account.Sell(selected.Name, selected.Stocks[i].Stock.Name, selected.Stocks[i].Quantity);
                    }
                    account.Portfolios.Remove(selected);
                    return;
                }
                else
                {
                    Console.WriteLine("Error, invalid input");
                }
            }
        }