Beispiel #1
0
        public ActionResult ChangeQuantityInBasket(ProductResult model)
        {
            HttpCookie cookie = Request.Cookies["Basket"];

            int productId = model.Id;
            int quantity = model.Quantity;
            int oldQuantity = Int16.Parse(cookie.Values[productId.ToString()]);
            string item = cookie.Values[productId.ToString()];

            if (item != null)
            {
                if (oldQuantity < quantity)
                {
                    var diff = quantity - oldQuantity;
                    cookie.Values[productId.ToString()] = (int.Parse(item) + diff).ToString();
                }
                else  if (oldQuantity > quantity)
                {
                    var diff = oldQuantity - quantity;
                    cookie.Values[productId.ToString()] = (int.Parse(item) - diff).ToString();
                }
            }

            Response.Cookies.Add(cookie);

            return RedirectToAction("Checkout");
        }
Beispiel #2
0
        public ActionResult AddToBasket(ProductResult model)
        {
            int productId = model.Id;
            int quantity = model.Quantity;

            if (Request.Cookies["Basket"] == null)
            {
                HttpCookie cookie = new HttpCookie("Basket");
                cookie.Values.Add(productId.ToString(), quantity.ToString());
                Response.Cookies.Add(cookie);
            }
            else
            {
                HttpCookie cookie = Request.Cookies["Basket"];

                string item = cookie.Values[productId.ToString()];

                if (item != null)
                    cookie.Values[productId.ToString()] = (int.Parse(item) + quantity).ToString();
                else
                    cookie.Values.Add(productId.ToString(), quantity.ToString());

                Response.Cookies.Add(cookie);
            }

            return RedirectToAction("Browse", new { category = model.Category.ToString().Trim() });
        }
Beispiel #3
0
        private ProductResult getDetailsFromId(int id)
        {
            ProductsDataContext db = new ProductsDataContext();
            var query = from p in db.Products
                        where p.Id == id
                        select new { p.Category, p.Description, p.Id, p.ImageUrl, p.Name, p.Price, p.Stock };

            var result = new ProductResult
            {
                Name = query.First().Name,
                Category = query.First().Category,
                Price = (double)query.First().Price,
                ImageUrl = query.First().ImageUrl,
                Description = query.First().Description,
                Stock = query.First().Stock,
                Id = query.First().Id
            };

            return result;
        }
Beispiel #4
0
        public List<ProductResult> getResultsByCategory(string category)
        {
            ProductsDataContext db = new ProductsDataContext();

            var query = from p in db.Products
                        where p.Category == category
                        select new { p.Category, p.Description, p.Id, p.ImageUrl, p.Name, p.Price, p.Stock };

            var results = new List<ProductResult>();

            foreach (var q in query)
            {
                var result = new ProductResult
                {
                    Name = q.Name,
                    Category = q.Category,
                    Price = (double)q.Price,
                    ImageUrl = q.ImageUrl,
                    Description = q.Description,
                    Stock = q.Stock,
                    Id = q.Id
                };

                results.Add(result);
            }
            return results;
        }
Beispiel #5
0
 public ActionResult Details(ProductResult model)
 {
     int id = model.Id;
     model = getDetailsFromId(id);
     return View("Details", model);
 }