Exemplo n.º 1
0
        public ActionResult Register([Bind(Include = "UserId,Email,Password,Forename,Surname,Address,Phone,PostCode,Country")] User user)
        {
            userRegistration.Country = Country_PM.GetCountries();


            if (ModelState.IsValid)
            {
                userPM.AddUser(user);

                Session["UserID"] = user.UserId.ToString();
                Session["Name"]   = user.Forename.ToString();

                if (Session[UserIDKey] != null)
                {
                    int userId = Convert.ToInt32(Session[UserIDKey]);
                    Cart_PM.MigrateCart(userId);
                }


                return(RedirectToAction("Index", "Home"));
            }


            return(View(userRegistration));
        }
Exemplo n.º 2
0
        public ActionResult Login(User user)
        {
            User userEmail = ModelContext.Users.Where(u => u.Email == user.Email).SingleOrDefault();

            if (userEmail != null)
            {
                CustomPasswordHasher customPasswordHasher = new CustomPasswordHasher();

                bool pass = customPasswordHasher.CustomVerifyHashedPassword(userEmail.Password, user.Password);

                User userCredentials = ModelContext.Users.Where(a => a.Email.Equals(user.Email)).FirstOrDefault();

                if (userCredentials != null && pass)
                {
                    Session["UserID"] = userCredentials.UserId.ToString();
                    Session["Name"]   = userCredentials.Forename.ToString();

                    if (Session[UserIDKey] != null)
                    {
                        int userId = Convert.ToInt32(Session[UserIDKey]);
                        Cart_PM.MigrateCart(userId);
                    }


                    return(RedirectToAction("Index", "Home"));
                }
            }

            ViewBag.Message = "Incorrect Credentials";
            return(View(user));
        }
Exemplo n.º 3
0
        public JsonResult EditCartSession([Bind(Include = "cartId,UserId,ProductId,Colour,Quantity,Price")] Cart cart, int id)
        {
            bool result = false;

            if (Session[CartSessionKey] != null)
            {
                Cart_PM.EditCartSession(cart, id);
                result = true;
            }

            return(Json(result));
        }
Exemplo n.º 4
0
        // GET: Carts/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Cart         cart         = new Cart();
            ShoppingCart shoppingCart = new ShoppingCart();


            // get cart either by session or from database
            if (Session[UserIDKey] != null)
            {
                cart = ModelContext.Carts.Find(id);
            }
            else
            {
                int index = id.GetValueOrDefault();
                cart = Cart_PM.GetCart().ElementAt(index);

                shoppingCart.CartSessionIndex = index;
            }


            if (cart == null)
            {
                return(HttpNotFound());
            }
            else
            {
                shoppingCart.Cart = cart;

                shoppingCart.Product = ModelContext.Products.Where(p => p.ProductId == cart.ProductId).SingleOrDefault();

                shoppingCart.ProductColours = (from d in ModelContext.ProductColours
                                               join f in ModelContext.ProductImages
                                               on d.ColourId equals f.ColourId
                                               where f.ProductId == cart.ProductId
                                               select d).Distinct();

                shoppingCart.ProductImages = ModelContext.ProductImages
                                             .Where(p => p.ProductId == cart.ProductId)
                                             .ToList();

                return(View(shoppingCart));
            }
        }
        public ApplicationController()
        {
            // if user is logged in
            if (System.Web.HttpContext.Current.Session[UserIdKey] != null)
            {
                UserIdSession = Convert.ToInt32(System.Web.HttpContext.Current.Session[UserIdKey]);

                Cart_PM.UserId = UserIdSession;

                ViewData["cart"] = Cart_PM.GetCartDb();

                ViewData["cartitemscount"] = Cart_PM.GetCartItemCountDb();

                ViewData["grandtotal"] = Cart_PM.GetGrandTotalDb();

                ViewData["product"] = Cart_PM.GetProductDb();

                ViewData["productimage"] = Cart_PM.GetProductImageDb();
            }
            else if (System.Web.HttpContext.Current.Session[CartSessionKey] != null)
            {
                ViewData["cart"] = Cart_PM.GetCartSession();

                ViewData["cartitemscount"] = Cart_PM.GetCartItemCountSession();

                ViewData["grandtotal"] = Cart_PM.GetGrandTotalSession();

                ViewData["product"] = Cart_PM.GetProductSession();

                ViewData["productimage"] = Cart_PM.GetProductImageSession();
            }
            else
            {
                ViewData["cart"] = null;

                ViewData["cartitemscount"] = 0;
            }


            // For page footer
            ViewData["categories"] = from pc in ModelContext.ProductCategories
                                     select pc;
        }
Exemplo n.º 6
0
        public JsonResult AddToCart([Bind(Include = "cartId,UserId,ProductId,Colour,Quantity,Price")] Cart cart)
        {
            bool result = false;
            int  userId = Convert.ToInt32(Session["UserId"]);

            if (ModelState.IsValid)
            {
                if (Session["UserId"] != null)
                {
                    Cart_PM.AddToCartDb(cart, userId);
                    result = true;
                }
                else
                {
                    Cart_PM.AddtoCartSession(cart);
                    result = true;
                }
            }

            return(Json(result));
        }
Exemplo n.º 7
0
        public JsonResult DeleteConfirmed(int id)
        {
            var cart = ModelContext.Carts
                       .Where(x => x.ProductId == id && (x.UserId == UserIdSession))
                       .SingleOrDefault();

            bool result = false;

            if (Session[UserIDKey] != null && cart != null)
            {
                ModelContext.Carts.Remove(cart);
                ModelContext.SaveChanges();
                result = true;
            }

            else if (Session[CartSessionKey] != null && cart != null)
            {
                Cart_PM.Remove(id);
                result = true;
            }

            return(Json(result));
        }