Beispiel #1
0
        protected string GetBasketText()
        {
            var helper = new BasketHelper();
            var basket = helper.GetBasket();

            return(string.Format("My Basket ({0})", helper.GetProductCount()));
        }
        public async Task OnGetAsync()
        {
            Basket   = BasketHelper.GetBasket(HttpContext.Session);
            Products = await _ds.GetProductsAsync();

            MainLayout.ShoppingBasket = Basket;
            ViewData["MainLayout"]    = MainLayout;
        }
Beispiel #3
0
        public async Task OnGetAsync()
        {
            if (ProductId != null)
            {
                Product = await _ds.GetProductByIdAsync(ProductId.Value);

                ProductQuantity = await _ds.GetProductStockAsync(ProductId.Value);
            }
            MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session);
            ViewData["MainLayout"]    = MainLayout;
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            helper = new BasketHelper();
            // Get basket based on tracker id
            basket = helper.GetBasket();

            if (basket != null)
            {
                rptProducts.DataSource = helper.GetAllProducts(basket);
                rptProducts.DataBind();
            }
        }
Beispiel #5
0
        public async Task OnGetAsync()
        {
            MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session);
            ViewData["MainLayout"]    = MainLayout;
            var userID = _um.GetUserId(User);
            var q      = await _ds.GetAllOrdersAsync();

            Orders = q.Where(o => o.UserID == userID);
            if (OrderId != 0)
            {
                Order = _ds.GetOrder(OrderId);
            }
        }
Beispiel #6
0
        protected void AddToCart_Click(object sender, EventArgs e)
        {
            var helper = new BasketHelper();
            var basket = helper.GetBasket();

            if (basket != null)
            {
                // TODO: This doesn't work if there's already a historical product..
                helper.AddProductToBasket(basket, Sitecore.Context.Item.Name, 1);
            }

            var url = Sitecore.Web.WebUtil.GetRawUrl();

            Response.Redirect(url + "?sc_trk={4BEEC42D-0349-4264-93E4-A14C4075CFEF}");
        }
Beispiel #7
0
        public async Task OnGetAsync()
        {
            MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session);
            ViewData["MainLayout"]    = MainLayout;


            Highlighted = await _ds.GetHighlightedProductsAsync();

            OnSale = await _ds.GetProductsOnSaleAsync();

            Latest = await _ds.GetLatestProductsAsync();

            BestSellingProducts = _ds
                                  .GetBestSellingProducts()

                                  .Select(p => _ds
                                          .GetProductById(p.ProductId));
        }
        public async Task <IActionResult> OnGetCheckStockAsync()
        {
            Basket = BasketHelper.GetBasket(HttpContext.Session);

            if (Basket.Items.Count == 0)
            {
                IsNotEmpty = false;
                return(Page());
            }
            else
            {
                IsNotEmpty = true;
            }

            Basket = BasketHelper.GetBasket(HttpContext.Session);

            foreach (var item in Basket.Items)
            {
                int stockBalance = await _ds.GetProductStockAsync(item.ProductId);

                if (item.Quantity > stockBalance)
                {
                    int length = item.Quantity - stockBalance;

                    for (int i = 0; i < length; i++)
                    {
                        BasketHelper.ModifyItem(HttpContext.Session, item.ProductId, false, false);
                    }
                    StockStatusOK      = false;
                    StockStatusUpdated = true;
                }
            }

            if (StockStatusOK)
            {
                return(RedirectToPage("/Checkout"));
            }

            Basket   = BasketHelper.GetBasket(HttpContext.Session);
            Products = await _ds.GetProductsAsync();

            MainLayout.ShoppingBasket = Basket;
            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(string toggleId = null)
        {
            if (!string.IsNullOrEmpty(toggleId))
            {
                Tags = AllergyTagHelper.LoadTags(HttpContext.Session);
                var tag = Tags.FirstOrDefault(t => t.Value == toggleId);
                tag.Selected = !tag.Selected;
                AllergyTagHelper.SaveTags(HttpContext.Session, Tags);
                return(RedirectToPage("./Categories", new { CategoryId = CategoryId }));
            }
            Categories = await _ds.GetProductCategoriesAsync();

            Tags = AllergyTagHelper.LoadTags(HttpContext.Session);
            if (Tags == null)
            {
                Tags = await _ds.GetTagsListAsync();

                AllergyTagHelper.SaveTags(HttpContext.Session, Tags);
            }
            if (CategoryId != null)
            {
                Products = await _ds.GetProductsByCategoryAsync(CategoryId.Value);

                CategoryName = Categories.FirstOrDefault(c => c.Id == CategoryId).Name;
                if (CategoryName == "Färdiga paket")
                {
                    Products = Products.OrderBy(o => o.Price);
                }
            }
            else
            {
                var list = await _ds.GetProductsAsync();

                Products = list.Where(c => c.Category.Name != "Färdiga paket").OrderBy(o => o.Name);
            }
            MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session);
            if (CategoryName != "Färdiga paket")
            {
                Products = _ds.FilteredProducts(Products, Tags);
            }
            ViewData["MainLayout"] = MainLayout;
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                Basket = BasketHelper.GetBasket(HttpContext.Session);
                Fail   = true;
                return(Page());
            }
            Basket = BasketHelper.GetBasket(HttpContext.Session);
            var   userId   = _um.GetUserId(User);
            Order newOrder = _ds.CreateOrderFromBasket(Basket, userId, Shipping.Value, Payment.Value);
            var   orderId  = _ds.SaveOrder(newOrder);

            foreach (var item in Basket.Items)
            {
                await _ds.DecreaseProductStockAsync(item.ProductId, item.Quantity);
            }
            BasketHelper.ClearBasket(HttpContext.Session);
            return(RedirectToPage("./CheckoutConfirm", new { orderid = orderId }));
        }
Beispiel #11
0
        public async Task <IActionResult> OnGetAsync(string toggleId = null)
        {
            if (!string.IsNullOrEmpty(toggleId))
            {
                Tags = AllergyTagHelper.LoadTags(HttpContext.Session);
                var tag = Tags.FirstOrDefault(t => t.Value == toggleId);
                tag.Selected = !tag.Selected;
                AllergyTagHelper.SaveTags(HttpContext.Session, Tags);
                return(RedirectToPage("./Search", new { Query = Query }));
            }

            Tags = AllergyTagHelper.LoadTags(HttpContext.Session);
            if (Tags == null)
            {
                Tags = await _ds.GetTagsListAsync();

                AllergyTagHelper.SaveTags(HttpContext.Session, Tags);
            }

            var products = await _ds.GetProductsAsync();

            if (!String.IsNullOrEmpty(Query))
            {
                SearchResults = products.Where(p => p.Name.ToUpper().Contains(Query.ToUpper()) && p.Category.Name != "Färdiga paket").ToList();
                if (SearchResults.Count() > 0)
                {
                    SearchResults = _ds.FilteredProducts(SearchResults, Tags);
                }
            }

            MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session);
            ViewData["MainLayout"]    = MainLayout;


            return(Page());
        }
 public void OnGet()
 {
     Basket = BasketHelper.GetBasket(HttpContext.Session);
     MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session);
     ViewData["MainLayout"]    = MainLayout;
 }