예제 #1
0
        private async Task <ShoppingListItem> GetFullItemInfo(ItemShoppingListLinkEntity itemlistlink, int storeId, CancellationToken ct)
        {
            var itemEntity = await _itemRepository.GetEntityAsync(itemlistlink.ItemId, ct);

            SpoonProductInformation spoonItem = GetSpoonItem(itemEntity.SpoonacularProductId);
            var itemStoreLink = await _itemStoreLinkRepository.GetEntityAsync(itemlistlink.ItemId, storeId, ct);

            var department = await _departmentRepository.GetEntityAsync(itemStoreLink.DepartmentId, ct);

            var lowerDepartment = await _lowerDepartmentRepository.GetEntityAsync(itemStoreLink.LowerDepartmentId, ct);

            var aisle = await _aisleRepository.GetEntityAsync(itemStoreLink.AisleId, ct);

            var section = await _sectionRepository.GetEntityAsync(itemStoreLink.SectionId, ct);

            var shelf = await _shelfRepository.GetEntityAsync(itemStoreLink.ShelfId, ct);

            var slot = await _shelfSlotsRepository.GetEntityAsync(itemStoreLink.SlotId, ct);


            ShoppingListItem item = new ShoppingListItem
            {
                LinkId            = itemlistlink.Id,
                Image             = "image.jpg",
                Name              = itemEntity.Name,
                Price             = itemStoreLink.Price,
                InStock           = itemStoreLink.InStock,
                StockAmount       = itemStoreLink.StockAmount,
                ItemQuantity      = itemlistlink.ItemQuantity,
                DepartmentId      = itemStoreLink.DepartmentId,
                Department        = department.Name,
                LowerDepartmentId = itemStoreLink.LowerDepartmentId,
                LowerDepartment   = lowerDepartment.Name,
                AisleId           = itemStoreLink.AisleId,
                Aisle             = aisle.Name,
                SectionId         = itemStoreLink.SectionId,
                Section           = section.Name,
                ShelfId           = itemStoreLink.ShelfId,
                Shelf             = shelf.ShelfNumber.ToString(),
                SlotId            = itemStoreLink.SlotId,
                Slot              = slot.SlotOnShelf.ToString()
            };

            if (spoonItem != null)
            {
                item.Image = spoonItem.images.First();
            }

            return(item);
        }
        public async Task <IActionResult> GetThreeItemsFromStore(int storeId, CancellationToken ct)
        {
            var itemStoreLinks = await _itemStoreLinkRepository.GetAllEntities(storeId, ct);

            List <Item> items = new List <Item>();

            foreach (var link in itemStoreLinks.Take(3))
            {
                //var itemEntity = await _itemRepository.GetEntityAsync(link.ItemId, ct);
                SpoonProductInformation spoonProduct = GetSpoonItem(link.Item.SpoonacularProductId);

                if (link.Item != null && spoonProduct != null)
                {
                    Item item = new Item
                    {
                        Id                 = link.ItemId,
                        LinkId             = link.Id,
                        Image              = spoonProduct.images.First(),
                        Name               = link.Item.Name,
                        Price              = link.Price,
                        InStock            = link.InStock,
                        StockAmount        = link.StockAmount,
                        DepartmentId       = link.DepartmentId,
                        LowerDepartmentId  = link.LowerDepartmentId,
                        AisleId            = link.AisleId,
                        SectionId          = link.SectionId,
                        ShelfId            = link.ShelfId,
                        SlotId             = link.SlotId,
                        ProductInformation = spoonProduct
                    };

                    items.Add(item);
                }
            }

            return(Ok(items));
        }
        public async Task <IActionResult> GetSections(int id, int storeId, CancellationToken ct)
        {
            var sections = _sectionRepository.GetAllEntities(id, ct);

            List <SectionAPP> sectionsAPP = new List <SectionAPP>();

            foreach (SectionEntity sec in sections)
            {
                var shelves = _shelfRepository.GetAllEntities(sec.Id, ct);
                sec.Shelves = shelves;
                SectionAPP section = new SectionAPP()
                {
                    Id            = sec.Id,
                    AisleId       = sec.AisleId,
                    Name          = sec.Name,
                    ItemsPerShelf = sec.ItemsPerShelf,
                    Shelves       = new List <ShelfAPP>()
                };

                foreach (ShelfEntity shelf in shelves)
                {
                    var shelfSlots = _shelfSlotsRepository.GetAllEntities(shelf.Id, ct);
                    shelf.Slots = shelfSlots;
                    ShelfAPP shelfapp = new ShelfAPP
                    {
                        Id          = shelf.Id,
                        SectionId   = shelf.SectionId,
                        ShelfNumber = shelf.ShelfNumber,
                        Slots       = new List <ShelfSlotAPP>()
                    };
                    foreach (var slot in shelfSlots)
                    {
                        var item = await _itemRepository.GetEntityAsync(slot.ItemId, ct);

                        var link = await _itemStoreLinkRepository.GetEntityAsync(item.Id, storeId, ct);

                        var department = await _departmentRepository.GetEntityAsync(link.DepartmentId, ct);

                        var lowerDepartment = await _lowerDepartmentRepository.GetEntityAsync(link.LowerDepartmentId, ct);

                        var aisle = await _aisleRepository.GetEntityAsync(link.AisleId, ct);

                        SpoonProductInformation spoonItem = GetSpoonItem(item.SpoonacularProductId);
                        Item itemapp = new Item
                        {
                            Id                 = item.Id,
                            LinkId             = link.Id,
                            Image              = "image.jpg",
                            Name               = item.Name,
                            Price              = link.Price,
                            InStock            = link.InStock,
                            StockAmount        = link.StockAmount,
                            DepartmentId       = link.DepartmentId,
                            LowerDepartmentId  = link.LowerDepartmentId,
                            AisleId            = link.AisleId,
                            SectionId          = link.SectionId,
                            ShelfId            = link.ShelfId,
                            SlotId             = link.SlotId,
                            LowerDepartment    = lowerDepartment.Name,
                            Aisle              = aisle.Name,
                            Section            = sec.Name,
                            Shelf              = shelf.ShelfNumber.ToString(),
                            Slot               = slot.SlotOnShelf.ToString(),
                            Department         = department.Name,
                            ProductInformation = spoonItem
                        };

                        if (spoonItem != null)
                        {
                            itemapp.Image = spoonItem.images.First();
                        }

                        ShelfSlotAPP slotApp = new ShelfSlotAPP
                        {
                            Id          = slot.Id,
                            ItemId      = slot.ItemId,
                            ShelfId     = slot.ShelfId,
                            SlotOnShelf = slot.SlotOnShelf,
                            Item        = itemapp
                        };

                        shelfapp.Slots.Add(slotApp);
                    }
                    section.Shelves.Add(shelfapp);
                }
                sectionsAPP.Add(section);
            }

            return(Ok(sectionsAPP));
        }