private string getCartId(HttpContextBase context)
        {
            string userId = User.Identity.GetUserId();

            if (userId == null)
            {
                userId = Guid.NewGuid().ToString();
            }

            if (context.Session[CART_SESSION_KEY] == null)
            {
                context.Session[CART_SESSION_KEY] = userId;
            }
            else if (context.Session[CART_SESSION_KEY].ToString() != userId)
            {
                string session = context.Session[CART_SESSION_KEY].ToString();
                var    items   = db.CartItems.Where(i => i.UserID == session).ToList();
                foreach (var item in items)
                {
                    item.UserID          = userId;
                    db.Entry(item).State = EntityState.Modified;
                }
                db.SaveChanges();
                context.Session[CART_SESSION_KEY] = userId;
            }
            return(context.Session[CART_SESSION_KEY].ToString());
        }
        // GET: Products/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            Category category = product.Category;

            if (category == null)
            {
                return(HttpNotFound());
            }

            product.Views++;
            db.Entry(product).State = EntityState.Modified;
            db.SaveChanges();
            return(View(new ProductDetailsViewModel {
                Product = product, Category = category
            }));
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "ID,Name")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Admin"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Description,WebPage,ImagePath,Country,DateFounded")] Manufacturer manufacturer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(manufacturer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Admin"));
     }
     return(View(manufacturer));
 }