Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Quantity,ProductId,ShoppingListId")] ListItem listItem)
        {
            if (id != listItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _listItemService.Edit(listItem);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ListItemExists(listItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "ShoppingLists", new { id = listItem.ShoppingListId }));
            }
            ViewData["ProductId"] = new SelectList(_productService.getAll(), "Id", "Name", listItem.ProductId);
            // ViewData["ShoppingListId"] = new SelectList(_context.ShoppingLists, "Id", "Id", listItem.ShoppingListId);
            return(View(listItem));
        }
Esempio n. 2
0
        public async Task <IActionResult> AddToCart(int id, int shpId)
        {
            var listItem = _listItemService.GetById(id);

            listItem.Result.InCart = !listItem.Result.InCart;

            try
            {
                await _listItemService.Edit(listItem.Result);
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return(RedirectToAction("Details", "ShoppingLists", new { id = shpId }));
        }
Esempio n. 3
0
        public async Task <IActionResult> RemoveProductsInCart(int idShoppingList)
        {
            var listItems = _listItemService.getAll().Result.Where(p => p.InCart == true && p.ShoppingListId == idShoppingList);

            foreach (var listItem in listItems)
            {
                try
                {
                    listItem.InCart = false;
                    await _listItemService.Edit(listItem);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }
            return(RedirectToAction("Index", "ShoppingLists"));
        }