Beispiel #1
0
        public async Task <IActionResult> Index()
        {
            var allproductslist = await webAPI.GetAllAsync <AllProductsViewModel>(ApiURL.PRODUCTS_DISCOUNT);

            var news = await webAPI.GetAllAsync <News>(ApiURL.NEWS_TOP5);

            HomeModel home = new HomeModel()
            {
                AllProducts = allproductslist,
                News        = news
            };

            return(View(home));
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            var cartId = HttpContext.Session.GetString(_cartSessionCookie);

            // Does user have a shoppingcart Id?
            if (cartId == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            // Are there any products in the cart??
            var content = await webAPI.GetAllAsync <OrderItemsModel>(ApiURL.CARTS_CONTENT + cartId);

            if (content.Count == 0)
            {
                return(RedirectToAction("Index", "ShoppingCart"));
            }

            // Is user logged in?
            if (User.Identity.IsAuthenticated)
            {
                orderviewmodel = await webAPI.GetOneAsync <OrderViewModel>(ApiURL.CARTS_CONTENT_PAY + $"{cartId}/{User.Identity.Name}");

                // Does user have a complete shippingaddress?
                if (!orderviewmodel.AddressComplete)
                {
                    TempData["Address Null"] = "Vänligen ange din adressinformation";
                }

                // Check if order contains products out of stock
                if (orderviewmodel.Products.Any(x => x.QuantityInStock - x.Amount < 0))
                {
                    TempData["QuantityOverload"] = "Din order innehåller ett större antal produkter än vad vi har på lager vilket påverkar leveranstiden.";
                }
            }
            else
            {
                TempData["LoginNeeded"] = "Du måste vara inloggad för att kunna handla...";
                return(RedirectToAction("Index", "ShoppingCart"));
            }

            OrderAndPaymentMethods.OrderViewModel = orderviewmodel;

            var token = await webAPIToken.New();

            OrderAndPaymentMethods.User = await webAPI.GetOneAsync <User>(ApiURL.USERS + User.Identity.Name, token);

            return(View(OrderAndPaymentMethods));
        }
Beispiel #3
0
        public async Task <IActionResult> Index()
        {
            var token = await webAPIToken.New();

            var allUserOrders = await webAPI.GetAllAsync <AllUserOrders>(ApiURL.ORDERS_BY_USER + User.Identity.Name, token);

            return(View(allUserOrders));
        }
        public async Task <IActionResult> Index()
        {
            if (HttpContext.Session.GetString(_cartSessionCookie) != null)
            {
                var cartId = HttpContext.Session.GetString(_cartSessionCookie);
                var result = await webAPI.GetAllAsync <OrderItemsModel>("https://localhost:44305/api/carts/content/" + cartId);

                return(View(result));
            }

            return(View());
        }
Beispiel #5
0
        public async Task <ActionResult <IEnumerable <AllProductsViewModel> > > Index(string searchtext)
        {
            List <AllProductsViewModel> products = new List <AllProductsViewModel>();

            // Anything to search for
            if (searchtext != null)
            {
                // Admin search
                if (User.Identity.IsAuthenticated && User.IsInRole("Admin"))
                {
                    var token = await webAPIToken.New();

                    products = await webAPI.GetAllAsync <AllProductsViewModel>(ApiURL.SEARCH_ADMIN + searchtext.ToLower(), token);
                }
                else
                {
                    products = await webAPI.GetAllAsync <AllProductsViewModel>(ApiURL.SEARCH + searchtext.ToLower());
                }

                return(View(products));
            }

            return(RedirectToAction("AllProducts", "Product"));
        }
Beispiel #6
0
 // Get all brands
 private async Task <List <Brand> > GetAllBrands()
 => await webAPI.GetAllAsync <Brand>(ApiURL.BRANDS);
Beispiel #7
0
        // Get all products based on category Id
        public async Task <ActionResult <List <AllProductsViewModel> > > Index(int catid)
        {
            // Get all products by category id
            List <AllProductsViewModel> categoryViewList = await webAPI.GetAllAsync <AllProductsViewModel>(ApiURL.PRODUCTS_IN_CAT + catid);

            // Get categoryname
            var category = await webAPI.GetOneAsync <Category>(ApiURL.CATEGORIES + catid);

            ViewBag.CategoryName = category.Name;

            return(View(categoryViewList));
        }
Beispiel #8
0
        public async Task <ActionResult> Index()
        {
            var news = await webAPI.GetAllAsync <News>(ApiURL.NEWS);

            return(View(news));
        }
        //private async Task<IEnumerable<Category>> GetAllCategoriesAsync()
        //    => await _context.Categories.ToListAsync();


        // Get all categories from the WebAPI
        private async Task <IEnumerable <Category> > GetAllCategoriesFromWebAPIAsync()
        {
            return(await webAPI.GetAllAsync <Category>("https://localhost:44305/api/categories"));
        }
Beispiel #10
0
 // Get all brands
 private async Task <List <Category> > GetAllCategories()
 => await webAPI.GetAllAsync <Category>(ApiURL.CATEGORIES);