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()); }
public async Task OnGet() { var userDetailsCookie = Request.Cookies["UserDetails"]; var cart = HttpContext.Session.GetString("cart"); if (userDetailsCookie != null) { LoggedInAs = await UserCookieHandler.GetUserAndCartByCookies(userDetailsCookie, cart); } }
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()); }
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()); }
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(); }
// 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)); }