Exemple #1
0
        public IActionResult EditSeed(int id)
        {
            var seed = _seedService.GetSeedById(id);

            if (seed.UserId != userId)
            {
                return(RedirectToAction("Index"));
            }

            var modelWarehouses     = _warehouseService.GetAllWarehouseForList(userId).Warehouses;
            var warehouseSelectList =
                modelWarehouses.Select(f => new SelectListItem(f.Name, Convert.ToString(f.Id))).ToList();

            seed.Warehouses = warehouseSelectList;

            return(View(seed));
        }
Exemple #2
0
        public IActionResult AddToCart(Guid id)
        {
            var currentCartItems = HttpContext.Session.Get <List <CartItem> >(sessionKeyCart);
            var sessionUserId    = HttpContext.Session.Get <Guid>(sessionKeyUserId);
            var actualUserId     = Guid.Parse(_userManager.GetUserId(User));

            List <CartItem> cartItems = new List <CartItem>();

            if (currentCartItems != null)
            {
                cartItems = currentCartItems;

                if (sessionUserId != actualUserId)
                {
                    currentCartItems = null;
                    HttpContext.Session.Clear();
                    cartItems = new List <CartItem>();
                }
            }

            HttpContext.Session.Set <Guid>(sessionKeyUserId, actualUserId);

            if (currentCartItems != null && currentCartItems.Any(x => x.Seed.SeedId == id))
            {
                int seedIndex = currentCartItems.FindIndex(x => x.Seed.SeedId == id);
                currentCartItems[seedIndex].Amount += 1;
                cartItems = currentCartItems;
            }
            else
            {
                var      seed    = _seedService.GetSeedById(id);
                CartItem newItem = new CartItem()
                {
                    Seed   = seed,
                    Amount = 1
                };

                cartItems.Add(newItem);
            }

            HttpContext.Session.Set <List <CartItem> >(sessionKeyCart, cartItems);

            return(RedirectToAction("Index"));
        }