示例#1
0
        public void OnGet()
        {
            EFdbService.LoadSampleData();
            Products  = EFdbService.GetProducts();
            ShoesOnly = ShoesService.GetShoesOnly();


            //People = db.People
            //    .Include(a => a.Purchases)
            //    .ThenInclude(b => b.Product)
            //    .ThenInclude(c => c.Reviews)
            //    ;

            //Products = db.Products;



            //Product p = products.Where(e => e.ShoeID == "0472503730009511").FirstOrDefault();
            //for (int i = 0; i < 3; i++)
            //{
            //    p.Stock--;
            //}
            //db.SaveChanges();



            // add ids in reviewservice here
            //ReviewsService.AddId();
        }
        public void OnGet()
        {
            //when no id is passed through url
            if (string.IsNullOrWhiteSpace(ProductId))
            {
                ProductId = "Invalid Id";
                validId   = false;
            }
            else
            {
                shoeSelectedDB = eFdb.GetProducts()
                                 .Where(x => x.ShoeID == ProductId)
                                 .FirstOrDefault <Product>();

                // get selected products shoe promos
                ShoePromos = eFdb.GetShoePromos(shoeSelectedDB.ShoeID);

                if (ShoePromos != null) // if promo shoes not null set bool promo true
                {
                    Promo = true;
                }

                if (Promo == true)
                {
                    ShuffleList.ShuffleThisList(ShoePromos);      // if there are promo matches shuffle the list so that new products are promoted each OnGet

                    ShoePromos     = ShoePromos.Take(3).ToList(); // only take the first three after shuffling the list
                    promoShoesOnly = eFdb.GetProducts();

                    foreach (var item in ShoePromos)
                    {
                        item.SelectPromoProduct = promoShoesOnly.Where(x => x.ShoeID == item.ShoeIdMatch).FirstOrDefault(); // store the product data onto the selected promo product
                    }
                }

                // if product id is a valid id then do
                if (shoeSelectedDB != null)
                {
                    validId = true;
                }
                else
                {
                    ProductId = "Invalid Id";
                    validId   = false;
                }
            }
        }
示例#3
0
        public IActionResult OnGetBuyNow(string id)
        {
            //var productModel = new ProductModel();
            IEnumerable <Product> productModel = EFdbService.GetProducts();

            cartItems = SessionHelper.GetObjectFromJson <List <CartItem> >(HttpContext.Session, CartSessionKey);
            if (cartItems == null)
            {
                cartItems = new List <CartItem>();
                cartItems.Add(new CartItem
                {
                    Product  = productModel.Where(p => p.ShoeID == id).FirstOrDefault(),
                    Quantity = 1,
                    CartId   = HttpContext.Session.Id,
                    ShoeId   = id
                });
                SessionHelper.SetObjectAsJson(HttpContext.Session, CartSessionKey, cartItems);
            }
            else
            {
                int index = Exists(cartItems, id);
                if (index == -1)
                {
                    cartItems.Add(new CartItem
                    {
                        Product  = productModel.Where(p => p.ShoeID == id).FirstOrDefault(),
                        Quantity = 1,
                        CartId   = HttpContext.Session.Id,
                        ShoeId   = id
                    });
                }
                else
                {
                    cartItems[index].Quantity++;
                }
                SessionHelper.SetObjectAsJson(HttpContext.Session, CartSessionKey, cartItems);
            }
            return(RedirectToPage("Cart"));
        }