Exemplo n.º 1
0
        public ShoppingListItem ConvertToShoppingListItem(ItemShoppingListLinkEntity itemShoppingListLink)
        {
            /*
             *     public class ShoppingListItem
             *     {
             *      public int Id { get; set; }
             *
             *      public string Image { get; set; }
             *
             *      public string Name { get; set; }
             *
             *      public decimal Price { get; set; }
             *
             *      public bool InStock { get; set; }
             *
             *      public int StockAmount { get; set; }
             *
             *      public string Aisle { get; set; }
             *
             *      public string Section { get; set; }
             *
             *      public int? QuantityBought { get; set; }
             *     }
             *
             */

            ShoppingListItem shoppingListItem = new ShoppingListItem();



            return(shoppingListItem);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostItemToList([FromBody] ItemListLink link, CancellationToken ct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var currentUser  = HttpContext.User;
            var userclaim    = currentUser.Claims.First();
            var userId       = Guid.Parse(userclaim.Value);
            var shoppingUser = await _shoppingUserRepository.GetEntityAsync(userId, ct);

            if (shoppingUser == null)
            {
                return(BadRequest("You are not a shopping user"));
            }

            ItemShoppingListLinkEntity itemlistlink = new ItemShoppingListLinkEntity
            {
                ItemId         = link.ItemId,
                ShoppingListId = link.ListId,
                ItemQuantity   = link.ItemQuantity
            };

            // Look up item in the store and make sure it is there.
            var item = await _itemStoreLinkRepository.GetEntityAsync(link.ItemId, shoppingUser.HomeStoreId, ct);

            if (item == null)
            {
                return(BadRequest("Item is not in the store"));
            }

            var shoppingList = await _shoppingListRepository.GetEntityAsync(link.ListId, ct);

            if (shoppingList.StoreId != shoppingUser.HomeStoreId)
            {
                return(BadRequest("List was not created for your current HomeStore"));
            }

            var linkAdded = await _itemListLinkRepository.AddNewLink(itemlistlink, ct);

            //var linksToShoppingList = await _itemListLinkRepository.GetAllByShoppingListId(link.ListId, ct);

            ShoppingListItem newShoppingListItem = new ShoppingListItem
            {
                LinkId = linkAdded.Id,
            };

            if (linkAdded != null)
            {
                return(Ok(newShoppingListItem));
            }

            return(BadRequest());
        }
Exemplo n.º 3
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 <ItemShoppingListLinkEntity> UpdateEntity(ItemShoppingListLinkEntity entity, CancellationToken ct)
        {
            try
            {
                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        //TODO: convert all this stuff and get the image from spoonacular
        private async Task <ShoppingListItem> ConvertToShoppingListItem(ItemShoppingListLinkEntity itemShoppingListLink, int storeId, CancellationToken ct)
        {
            /*
             *     public class ShoppingListItem
             *     {
             *      public int Id { get; set; }
             *
             *      public string Image { get; set; }
             *
             *      public string Name { get; set; }
             *
             *      public decimal Price { get; set; }
             *
             *      public bool InStock { get; set; }
             *
             *      public int StockAmount { get; set; }
             *
             *      public string Aisle { get; set; }
             *
             *      public string Section { get; set; }
             *
             *      public int QuantityBought { get; set; }
             *     }
             *
             */

            ItemEntity itemEntity = await _itemRepository.GetEntityAsync(itemShoppingListLink.ItemId, ct);

            ItemStoreLinkEntity itemStoreLink = await _itemStoreLinkRepository.GetEntityAsync(itemEntity.Id, storeId, ct);

            ShoppingListItem shoppingListItem = new ShoppingListItem
            {
                LinkId       = itemShoppingListLink.Id,
                Name         = itemEntity.Name,
                Price        = itemStoreLink.Price,
                InStock      = itemStoreLink.InStock,
                StockAmount  = itemStoreLink.StockAmount,
                ItemQuantity = itemShoppingListLink.ItemQuantity
            };

            return(shoppingListItem);
        }
        public async Task <bool> DeleteEntity(int id, CancellationToken ct)
        {
            try
            {
                ItemShoppingListLinkEntity islink = await _dbContext.ItemShoppingListLinks.FirstOrDefaultAsync(il => il.Id == id);

                if (islink == null)
                {
                    throw new Exception("Item Shopping List Link Does not Exist");
                }

                _dbContext.ItemShoppingListLinks.Remove(islink);
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
        public async Task <ItemShoppingListLinkEntity> AddNewLink(ItemShoppingListLinkEntity entity, CancellationToken ct)
        {
            try
            {
                ItemShoppingListLinkEntity islink = await _dbContext.ItemShoppingListLinks.FirstOrDefaultAsync(il => il.ItemId == entity.ItemId && il.ShoppingListId == entity.ShoppingListId);

                if (islink != null)
                {
                    throw new Exception("Already have that item in your shopping list");
                }

                await _dbContext.ItemShoppingListLinks.AddAsync(entity);

                await _dbContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
 Task <bool> IRepository <ItemShoppingListLinkEntity> .AddEntityAsync(ItemShoppingListLinkEntity entity, CancellationToken ct)
 {
     throw new NotImplementedException();
 }