private void itemSoldUpdateStore(Dictionary <string, LocationSales> salesStore, string location, string sku, int n)
        {
            //Look up the price
            Price p = getPrice(location, sku);
            //Lookup sales aggregates
            LocationSales localSales;

            if (!salesStore.TryGetValue(location, out localSales))
            {
                localSales = new LocationSales();
                salesStore.Add(location, localSales);
            }

            localSales.itemSold(sku, p.costPrice, p.sellingPrice, n);
        }
        public ApplicationState()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                Microsoft.Azure.CloudConfigurationManager.GetSetting("StorageConnectionString"));

            Config.storageAccount = storageAccount;

            itemStore = new Dictionary <string, Dictionary <string, Item> >();

            prices = new Dictionary <string, Dictionary <string, Price> >();

            sales        = new Dictionary <string, LocationSales>();
            dailySales   = new Dictionary <string, LocationSales>();
            monthlySales = new Dictionary <string, LocationSales>();

            allsales = new LocationSales();
        }
        //Summary over all locations
        public async Task <ActionResult> Summary()
        {
            ApplicationState state = await ApplicationState.getApplicationState();

            ViewBag.totalCp = state.getForeverCP();
            ViewBag.totalSp = state.getForeverSP();

            LocationSales        allSales = state.getSalesOverAllLocations();
            List <ItemSalesInfo> data     = new List <ItemSalesInfo>();

            foreach (var i in allSales.sales)
            {
                data.Add(new ItemSalesInfo()
                {
                    name         = i.Key,
                    foreverCP    = (double)i.Value.foreverCP,
                    foreverSP    = (double)i.Value.foreverSP,
                    quantitySold = i.Value.quantitySold
                });
            }
            ;
            return(View(data));
        }
        //Summary for a single location
        public async Task <ActionResult> DailySummary(string id)
        {
            ViewBag.message = true;
            if (id == null)
            {
                ViewBag.message = false;
                return(View());
            }

            try
            {
                string           location = id;
                ApplicationState state    = await ApplicationState.getApplicationState();

                LocationSales        localSales = state.getDailySalesForLocation(location);
                List <ItemSalesInfo> data       = new List <ItemSalesInfo>();
                foreach (var i in localSales.sales)
                {
                    data.Add(new ItemSalesInfo()
                    {
                        name         = i.Key,
                        foreverCP    = (double)i.Value.foreverCP,
                        foreverSP    = (double)i.Value.foreverSP,
                        quantitySold = i.Value.quantitySold
                    });
                }
                ;

                ViewBag.location = location;
                return(View(data));
            }
            catch (Exception e)
            {
                ViewBag.message = false;
                return(View());
            }
        }