Beispiel #1
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var objList = _wishDRepo.GetAll(u => u.ApplicationUserId == claim.Value).Join(_prodRepo.GetAll(),
                                                                                          w => w.ProductId,
                                                                                          p => p.Id,
                                                                                          (wish, product) => new
            {
                wishListId   = wish.Id,
                productName  = product.Name,
                productPrice = product.Price,
                productStock = product.Stock,
                productId    = product.Id
            });
            List <WishListVM> WishListVM = new List <WishListVM>();

            foreach (var details in objList)
            {
                WishListVM wishList = new WishListVM()
                {
                    Id          = details.wishListId,
                    ProductId   = details.productId,
                    ProductName = details.productName,
                    UnitPrice   = details.productPrice,
                    Stock       = details.productStock
                };
                WishListVM.Add(wishList);
            }
            return(View(WishListVM));
        }
Beispiel #2
0
        public IActionResult Index()
        {
            var    claimsIdentity = (ClaimsIdentity)User.Identity;
            var    claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            HomeVM homeVM         = new HomeVM()
            {
                Products   = _prodRepo.GetAll(includeProperties: "Category"),
                Categories = _catRepo.GetAll(),
                OrderHList = _orderHRepo.GetAll()
            };

            if (User.IsInRole(WC.CustomerRole))
            {
                homeVM.CartList      = _cartRepo.GetAll(u => u.ApplicationUserId == claim.Value);
                homeVM.WishListItems = _wishDRepo.GetAll(u => u.ApplicationUserId == claim.Value);

                List <ShoppingCart> shoppingCartList = new List <ShoppingCart>();

                foreach (var item in homeVM.CartList)
                {
                    var obj = shoppingCartList.FirstOrDefault(u => u.ProductId == item.ProductId);
                    if (obj == null)
                    {
                        //cart item doesnot exist in session add it to session
                        shoppingCartList.Add(new ShoppingCart {
                            ProductId = item.ProductId, Qty = item.Qty
                        });
                    }
                }
                HttpContext.Session.Set(WC.SessionCart, shoppingCartList);


                List <WishList> wishLists = new List <WishList>();
                foreach (var item in homeVM.WishListItems)
                {
                    var obj = wishLists.FirstOrDefault(u => u.ProductId == item.ProductId);
                    if (obj == null)
                    {
                        // Product doesnot exist in wishlist session add it to session
                        wishLists.Add(new WishList {
                            ProductId = item.ProductId
                        });
                    }
                }
                HttpContext.Session.Set(WC.WishList, wishLists);


                return(View(homeVM));
            }
            else
            {
                return(View(homeVM));
            }
        }