Ejemplo n.º 1
0
 private void AddNewStock()
 {
     Stocks.Add(NewStock);
     NewStock.ValidateAll();
     BondQuantity           = Stocks.Count(p => p.StockType == StockType.BondTypeName);
     EquityQuantity         = Stocks.Count(p => p.StockType == StockType.EquityTypeName);
     TotalBondMarketValue   = Stocks.Where(p => p.StockType == StockType.BondTypeName).Sum(s => s.MarketValue ?? 0);
     TotalEquityMarketValue = Stocks.Where(p => p.StockType == StockType.EquityTypeName).Sum(s => s.MarketValue ?? 0);
     TotalBondWeight        = Stocks.Where(p => p.StockType == StockType.BondTypeName).Sum(s => s.StockWeight ?? 0);
     TotalEquityWeight      = Stocks.Where(p => p.StockType == StockType.EquityTypeName).Sum(s => s.StockWeight ?? 0);
     TotalQuantity          = Stocks.Count;
     TotalMarketValue       = Stocks.Sum(s => s.MarketValue ?? 0);
     TotalWeight            = Stocks.Sum(s => s.StockWeight ?? 0);
     NewStock.Model.Notify("StockTypeQuantity", NewStock.Model.StockType == StockType.BondTypeName ? BondQuantity : EquityQuantity);
     ClearStockData();
 }
        public async Task ExecuteLoadElementsCommand()
        {
            Products = await DataStore.GetProductsAsync();

            decimal totalCostAccumulator        = 0;
            decimal totalRetailValueAccumulator = 0;

            decimal phoneStocksCostAccumulator     = 0;
            decimal accessoryStocksCostAccumulator = 0;

            int phoneStockCounter     = 0;
            int AccessoryStockCounter = 0;

            Stocks = await StoreDataStore.GetStoreStocksAsync(App.currentStore.StoreId, true);

            foreach (Stock stock in Stocks)
            {
                Product product = Products.FirstOrDefault(x => x.Id == stock.ProductId);
                totalCostAccumulator        += (product.Cost * stock.Quantity);
                totalRetailValueAccumulator += (product.Cost * stock.Quantity);

                if (product.ProductType.ToLower() == "phone")
                {
                    phoneStockCounter          += stock.Quantity;
                    phoneStocksCostAccumulator += (product.Cost * stock.Quantity);
                }
                else
                {
                    AccessoryStockCounter          += stock.Quantity;
                    accessoryStocksCostAccumulator += (product.Cost * stock.Quantity);
                }
            }

            StoreTotalStockCost = Stocks.Count().ToString();

            StorePhoneStocksCount     = phoneStockCounter.ToString();
            StoreAccessoryStocksCount = AccessoryStockCounter.ToString();

            StoreStocksTotalRetailValue   = totalRetailValueAccumulator.ToString();
            StoreTotalPhoneStocksCost     = phoneStocksCostAccumulator.ToString();
            StoreTotalAccessoryStocksCost = accessoryStocksCostAccumulator.ToString();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to add stocks to the collection
        /// </summary>
        /// <param name="obj"></param>
        private void AddStock(object obj)
        {
            if (Price == null)
            {
                return;
            }
            if (Price == null)
            {
                return;
            }
            if (Stocks == null)
            {
                Stocks = new ObservableCollection <Stock>();
            }
            try
            {
                string name = $"{StockType.ToString()}{Stocks.Where(x => x.StockType == stockType).Count() + 1}";
                Stocks.Add(new Stock()
                {
                    StockType = this.StockType,
                    Name      = name,
                    Price     = (float)this.Price,
                    Quantity  = (float)this.Quantity
                });

                UpdateEquitySummary();
                UpdateBondSummary();
                TotalMarketValue    = Stocks.Select(x => x.MarketValue).Sum();
                TotalNumberOfStocks = Stocks.Count();
                TotalStockWeight    = Stocks.Select(x => x.StockWeight).Sum();
                UpdateStockWeight();
                OnPropertyChanged("Stocks");
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception - AddStock, Details : {ex.Message}");
            }
        }