public async Task <IActionResult> Edit(int id, [Bind("ShoppingListLineID,ListID,ProductID,Quantity")] ShoppingListLine shoppingListLine)
        {
            if (id != shoppingListLine.ShoppingListLineID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shoppingListLine);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShoppingListLineExists(shoppingListLine.ShoppingListLineID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoppingListLine));
        }
        public async Task <IActionResult> Create([Bind("ShoppingListLineID,ListID,ProductID,ProductName,Quantity")] ShoppingListLine shoppingListLine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoppingListLine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoppingListLine));
        }
        public async Task <IActionResult> AddToList(int ProductID, string userName)
        {
            var user = await _userManager.FindByNameAsync(userName);

            //var join = from pid in _context.Product
            //           join cat in _context.Category on pid.CategoryID equals cat.CategoryID
            //           where pid.ProductID == ProductID
            //           select new { name = pid.ProductName, id = pid.ProductID };

            //string name = join.FirstOrDefault(line => line.id == ProductID).name;



            Product product = _context.Product
                              .FirstOrDefault(p => p.ProductID == ProductID);

            if (product != null)
            {
                ShoppingListLine line = _context.ShoppingListLine
                                        .Where(p => p.ProductID == ProductID && p.ListID.Equals(user.ListID))
                                        .FirstOrDefault();

                var list = (from aisle in _context.Aisle
                            where aisle.StoreID == user.StorePref && aisle.CategoryID == product.CategoryID
                            select new { aisle.AisleNumber }).ToList();

                if (line == null)
                {
                    _context.ShoppingListLine.Add(new ShoppingListLine
                    {
                        ListID      = user.ListID,
                        ProductID   = ProductID,
                        ProductName = product.ProductName,
                        Quantity    = 1
                    });;
                }
                else
                {
                    line.Quantity += 1;
                }
            }



            //ViewBag.ListID = user.ListID;
            //ViewBag.ProductID = ProductID;
            //ViewBag.Name = name;

            //string name = join.FirstOrDefault(line => line.id == ProductID).name;
            //ViewBag.ListID = ListID;
            //ViewBag.ProductID = ProductID;
            //ViewBag.Name = name;

            //var newitem = new ShoppingListLine
            //{
            //    ListID = user.ListID,
            //    ProductID = ProductID,
            //    ProductName = name,
            //    Quantity = 1
            //};

            //_context.ShoppingListLine.Add(newitem);


            await _context.SaveChangesAsync();

            //return View();
            return(RedirectToAction("YourList", "ShoppingListLines"));//, new { userName = user.Email }
        }