public void addGroceryListItem(GroceryList g, Item i)
        {
            GroceryListItem gi = new GroceryListItem();

            gi.GroceryList = g;
            gi.Item        = i;
            _groceryContext.GroceryListItems.Add(gi);
            _groceryContext.SaveChanges();
        }
        //public void addGroceryListItem(GroceryList g, Item i)
        //{
        //    GroceryListItem gi = new GroceryListItem();

        //    gi.GroceryList = g;
        //    gi.Item = i;
        //    _groceryContext.GroceryListItems.Add(gi);
        //    _groceryContext.SaveChanges();
        //}

        public void addGroceryListItem(int gID, int iID)
        {
            GroceryListItem gi = new GroceryListItem();

            gi.GroceryList = _groceryContext.GroceryLists.Where(g => g.GroceryListId == gID).FirstOrDefault();
            gi.Item        = _groceryContext.Items.Where(m => m.ItemId == iID).FirstOrDefault();
            _groceryContext.GroceryListItems.Add(gi);
            _groceryContext.SaveChanges();
        }
예제 #3
0
        public async Task Edit(GroceryListItem _groceryListItem)
        {
            var _groceryListItemToEdit = await GetById(_groceryListItem.Id);

            if (_groceryListItemToEdit != null)
            {
                _groceryListItemToEdit.Quantity      = _groceryListItem.Quantity;
                _groceryListItemToEdit.DateCreated   = _groceryListItem.DateCreated;
                _groceryListItemToEdit.GroceryListId = _groceryListItem.GroceryListId;
                _groceryListItemToEdit.ProductId     = _groceryListItem.ProductId;

                await _context.SaveChangesAsync();
            }
        }
예제 #4
0
        public async Task <ActionResult <GroceryListItem> > GetGroceryListItem(int id)
        {
            var listItem = await _groceryListItemService.GetById(id);

            if (listItem == null)
            {
                return(NotFound());
            }

            var _listItem = new GroceryListItem()
            {
                Id           = listItem.Id,
                Quantity     = listItem.Quantity,
                DateCreated  = listItem.DateCreated,
                ProductTitle = listItem.Product.Title,
                ProductSlug  = listItem.Product.Slug,
                ProductImage = Image.Generate(listItem.Product.ImageData, listItem.Product.ImageType)
            };

            return(Ok(_listItem));
        }
예제 #5
0
        public void Adding_an_item_adds_an_item()
        {
            var itemsBefore = _viewModel.Items.Count;

            _viewModel.CurrentGroceryListItem.Name     = "Fish";
            _viewModel.CurrentGroceryListItem.Quantity = 1;

            GroceryListItem added = null;

            _viewModel.Items.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Add)
                {
                    added = (GroceryListItem)args.NewItems[0];
                }
            };

            _viewModel.AddItemCommand.Execute(null);

            Assert.Equal(itemsBefore + 1, _viewModel.Items.Count);
            Assert.NotNull(added);
        }
예제 #6
0
        public async Task <ActionResult <IEnumerable <GroceryListItem> > > GetGroceryListItemByGroceryListId(int groceryListId)
        {
            var listItems = await _groceryListItemService.GetByGroceryListId(groceryListId);

            GroceryListItem _listItem;
            var             _listItems = new List <GroceryListItem>();

            foreach (var item in listItems)
            {
                _listItem = new GroceryListItem()
                {
                    Id           = item.Id,
                    Quantity     = item.Quantity,
                    DateCreated  = item.DateCreated,
                    ProductTitle = item.Product.Title,
                    ProductSlug  = item.Product.Slug,
                    ProductImage = Image.Generate(item.Product.ImageData, item.Product.ImageType)
                };

                _listItems.Add(_listItem);
            }

            return(Ok(_listItems));
        }
예제 #7
0
 public async Task <GroceryListItem> Delete(GroceryListItem groceryListItem)
 {
     return(await _groceryListItemRepository.Delete(groceryListItem.Id));
 }
예제 #8
0
 public async Task <GroceryListItem> Update(GroceryListItem groceryListItem)
 {
     return(await _groceryListItemRepository.Update(groceryListItem));
 }
예제 #9
0
 public async Task <GroceryListItem> Add(GroceryListItem groceryListItem)
 {
     groceryListItem.IsCollected = false;
     return(await _groceryListItemRepository.Add(groceryListItem));
 }
예제 #10
0
 public Task <int> Save(GroceryListItem groceryListItem)
 {
     groceryListItem.Id = _nextId++;
     _items.Add(groceryListItem);
     return(Task.FromResult(groceryListItem.Id));
 }
예제 #11
0
        public async Task Create(GroceryListItem _groceryListItem)
        {
            await _context.GroceryListItems.AddAsync(_groceryListItem);

            await _context.SaveChangesAsync();
        }