Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            var userDetailsCookie = Request.Cookies["UserDetails"];

            if (userDetailsCookie == null)
            {
                return(RedirectToPage("/login"));
            }
            var cart = HttpContext.Session.GetString("cart");

            LoggedInAs = await UserCookieHandler.GetUserAndCartByCookies(userDetailsCookie, cart);

            if (LoggedInAs.Role != "Admin")
            {
                return(RedirectToPage("/index"));
            }

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

            Category = await _context.Categories.FirstOrDefaultAsync(c => c.ID == id);

            if (Category == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 2
0
        public async Task OnGet()
        {
            var userDetailsCookie = Request.Cookies["UserDetails"];
            var cart = HttpContext.Session.GetString("cart");

            if (userDetailsCookie != null)
            {
                LoggedInAs = await UserCookieHandler.GetUserAndCartByCookies(userDetailsCookie, cart);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGet()
        {
            var userDetailsCookie = Request.Cookies["UserDetails"];
            var cart = HttpContext.Session.GetString("cart");

            if (userDetailsCookie != null)
            {
                LoggedInAs = await UserCookieHandler.GetUserAndCartByCookies(userDetailsCookie, cart);
            }

            Product          = _productRepository.GetProductById(SelectedProduct);
            AllCategories    = _categoryRepository.GetAllCategorys().ToList();
            MatchingProducts = _productRepository.GetProductsByCategory(Product.Category.TypeName).ToList();

            return(Page());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnGet()
        {
            var userDetailsCookie = Request.Cookies["UserDetails"];

            if (userDetailsCookie == null)
            {
                return(RedirectToPage("Login"));
            }
            var cart = HttpContext.Session.GetString("cart");

            LoggedInAs = await UserCookieHandler.GetUserAndCartByCookies(userDetailsCookie, cart);

            if (LoggedInAs.Role != "Admin")
            {
                return(RedirectToPage("/index"));
            }

            return(Page());
        }
Exemplo n.º 5
0
        public async Task OnGet()
        {
            var userDetailsCookie = Request.Cookies["UserDetails"];
            var cart = HttpContext.Session.GetString("cart");

            if (userDetailsCookie != null)
            {
                LoggedInAs = await UserCookieHandler.GetUserAndCartByCookies(userDetailsCookie, cart);
            }

            TopSalesTop5       = _productRepository.GetMostSoldProducts();
            LatestArrivals     = _productRepository.GetLatestArrivals();
            DiscountedProducts = _productRepository.GetDiscountedProducts();

            _userRepository.CheckForAdmin();
            AllProducts         = _productRepository.GetAllProducts().ToList();
            AllCategories       = _categoryRepository.GetAllCategorys().ToList();
            AllSelectedProducts = _productRepository.GetProductsByCategory(SelectedCategory).ToList();
        }
Exemplo n.º 6
0
        // Lägg till i varukorg klickad
        public async Task <IActionResult> OnPostAdd(Guid id)
        {
            var userDetailsCookie = Request.Cookies["UserDetails"];

            AllCategories = _categoryRepository.GetAllCategorys().ToList();

            if (userDetailsCookie != null)
            {
                LoggedInAs = await UserCookieHandler.GetUserByCookie(userDetailsCookie);

                Product          = _productRepository.GetProductById(id);
                MatchingProducts = _productRepository.GetProductsByCategory(Product.Category.TypeName).ToList();

                var cart = HttpContext.Session.GetString("cart");
                if (cart != null)
                {
                    var productCart = await UserCookieHandler.GetProductCartByCookie(cart);

                    productCart.Add(Product);
                    var productIds = productCart.Select(product => product.ID).ToList();
                    HttpContext.Session.SetString("cart", JsonSerializer.Serialize(productIds));
                }
                else
                {
                    var productIds = new List <Guid> {
                        Product.ID
                    };
                    HttpContext.Session.SetString("cart", JsonSerializer.Serialize(productIds));
                }
            }
            else
            {
                return(RedirectToPage("/Login"));
            }
            return(Redirect("/ProductView?SelectedProduct=" + id));
        }