Example #1
0
        public async Task <IList <CellarSummaryModel> > GetCellarList()
        {
            var cellars     = new List <CellarSummaryModel>();
            var cellarTable = TableClient.GetTableReference("Cellar");

            TableQuery <AzureTableCellarModel> query = new TableQuery <AzureTableCellarModel>();
            var cellarsBriefDetail = new List <CellarSummaryModel>();
            var aztCellars         = await cellarTable.ExecuteQueryAsync(query);

            foreach (var aztCellar in aztCellars)
            {
                var cellar = new CellarSummaryModel()
                {
                    CellarId = new AzureTableKey()
                    {
                        RowKey       = aztCellar.RowKey,
                        PartitionKey = aztCellar.PartitionKey,
                        TimeStamp    = aztCellar.Timestamp
                    },
                    Name        = aztCellar.Name,
                    Description = aztCellar.Description,
                    Capacity    = aztCellar.Capacity
                };
                cellar.BottleCount = await GetCellarBottleCount(cellar.CellarId);

                cellars.Add(cellar);
            }

            return(cellars);
        }
Example #2
0
        private static async Task <InventoryCellarModel> ProcessCellar(CellarSummaryModel cellar)
        {
            var inventoryCellar = new InventoryCellarModel()
            {
                CellarName  = cellar.Name,
                Capacity    = cellar.Capacity,
                BottleCount = 0
            };

            inventoryCellar = await ProcessBottles(inventoryCellar, cellar);

            inventoryCellar.PctCapacity = inventoryCellar.Capacity == 0 ? "0" : (Convert.ToDouble((inventoryCellar.BottleCount) / Convert.ToDouble(inventoryCellar.Capacity))).ToString("P");
            return(inventoryCellar);
        }
Example #3
0
        private static async Task <InventoryCellarModel> ProcessBottles(InventoryCellarModel InventoryCellar, CellarSummaryModel Cellar)
        {
            var vintageList            = new List <InventoryVintageModel>();
            var WineItemList           = new List <InventoryWineItemModel>();
            var VintageListItem        = new InventoryVintageModel();
            var GetInventoryReportData = await CloudData.GetCellarSummaryBottles(Cellar.CellarId);

            if (GetInventoryReportData.GetType() == typeof(List <BottleBriefDataModel>))
            {
                Cellar.Bottles = GetInventoryReportData;
            }
            foreach (var bottle in Cellar.Bottles)
            {
                InventoryCellar.BottleCount++;
                var vintageListItem = (from yearItem in vintageList
                                       where yearItem.VinetageYear == bottle.Vintage
                                       select yearItem).FirstOrDefault();
                if (vintageListItem != null && vintageListItem.WineItems != null)
                {
                    //already have a collection established for the vintage with at least
                    //one WineItem in it.
                    VintageListItem = vintageListItem;
                    WineItemList    = VintageListItem.WineItems.ToList();
                }
                else
                {
                    //need to create the Vintage List Item object
                    var newVintageItem = new InventoryVintageModel()
                    {
                        VinetageYear = bottle.Vintage,
                        WineItems    = new List <InventoryWineItemModel>().AsEnumerable()
                    };
                    VintageListItem = newVintageItem; //change scope in case of another bottle of same type
                    vintageList.Add(VintageListItem);
                    WineItemList = VintageListItem.WineItems.ToList();
                }
                var wineBottleRowKey = bottle.BottleId.RowKey.Substring(bottle.BottleId.RowKey.IndexOf("-") + 1);
                wineBottleRowKey = wineBottleRowKey.Substring(0, wineBottleRowKey.LastIndexOf("-"));
                var itemInList = (from item in WineItemList
                                  where item.WineBottleRowKey == wineBottleRowKey
                                  select item).FirstOrDefault();
                if (itemInList != null)
                {
                    //at least one other bottle exists in List
                    itemInList.Quantity++;
                    itemInList.UnitValue = itemInList.UnitValue < bottle.PricePaid ? bottle.PricePaid :
                                           itemInList.UnitValue < bottle.RetailPrice ? bottle.RetailPrice : itemInList.UnitValue;
                    itemInList.TotalValue = itemInList.UnitValue * itemInList.Quantity;
                    if (!string.IsNullOrEmpty(bottle.BarCode))
                    {
                        var barCodeList = itemInList.BarCodes.ToList();
                        barCodeList.Add(bottle.BarCode);
                        itemInList.BarCodes = barCodeList.AsEnumerable();
                    }
                }
                else
                {
                    //first bottle of this type
                    var newItem = new InventoryWineItemModel()
                    {
                        Quantity         = 1,
                        Size             = bottle.Size,
                        WineryName       = bottle.WineryName,
                        WineName         = bottle.WineName,
                        Country          = bottle.CountryOfOrigin,
                        Region           = bottle.Region,
                        Color            = bottle.Color,
                        VarietalType     = bottle.VarietalType,
                        UnitValue        = bottle.RetailPrice > 0 ? bottle.PricePaid > bottle.RetailPrice ? bottle.PricePaid : bottle.RetailPrice : 30d,
                        TotalValue       = bottle.RetailPrice > 0 ? bottle.PricePaid > bottle.RetailPrice ? bottle.PricePaid : bottle.RetailPrice : 30d,
                        WineBottleRowKey = wineBottleRowKey
                    };
                    if (!string.IsNullOrEmpty(bottle.BarCode))
                    {
                        var btlBarCodeList = new List <string>()
                        {
                            bottle.BarCode
                        };
                        newItem.BarCodes = btlBarCodeList.AsEnumerable();
                    }
                    WineItemList.Add(newItem);
                }

                VintageListItem.WineItems        = WineItemList.AsEnumerable();
                VintageListItem.VinetageValue    = WineItemList.Sum(tv => tv.TotalValue);
                InventoryCellar.Vintages         = vintageList.AsEnumerable();
                InventoryCellar.CellarTotalValue = InventoryCellar.Vintages.Sum(cv => cv.VinetageValue);
            }
            return(InventoryCellar);
        }