Exemple #1
0
        public ActionResult OrderPlaced(PersonInfo model)
        {
            model.UserId = Convert.ToInt32(Request.Form["userid"]);
            model.PIId   = Convert.ToInt32(Request.Form["pid"]);
            var db = new FootWearDb();

            db.PersonInfoes.Attach(model);
            db.Entry(model).State = System.Data.EntityState.Modified;
            db.SaveChanges();
            var m = db.Carts.Where(u => u.UserId.Equals(model.UserId)).ToList();

            for (int i = 0; i < m.Count; i++)
            {
                m[i].IsActive = false;
                db.Carts.Attach(m[i]);
                db.Entry(m[i]).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            var products = db.Carts.Where(u => u.UserId.Equals(model.UserId) && u.IsActive == true).ToList();

            if (products.Count == 0)
            {
                TempData["Success"] = "Successfully!";
            }
            else
            {
                TempData["Success"] = "Unsuccessfully!";
            }
            return(View());
        }
Exemple #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    var db = new FootWearDb();
                    db.webpages_UsersInRoles.Add(new webpages_UsersInRoles {
                        RoleId = 2, UserId = WebSecurity.GetUserId(User.Identity.Name)
                    });
                    db.SaveChanges();
                    db.PersonInfoes.Add(new PersonInfo {
                        UserId = WebSecurity.GetUserId(User.Identity.Name), FirstName = model.UserName
                    });
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #3
0
        public ActionResult AddToCart()
        {
            int uid = WebSecurity.GetUserId(User.Identity.Name);
            int pId = Convert.ToInt32(Request.Form["pid"]);

            if (Request.IsAuthenticated == true)
            {
                var  db = new FootWearDb();
                var  m  = db.Products.Where(u => u.PId.Equals(pId)).FirstOrDefault();
                Cart c  = new Cart();
                c.PId      = pId;
                c.Name     = m.PName;
                c.Price    = m.Price;
                c.Image    = m.PImage;
                c.UserId   = uid;
                c.IsActive = true;
                var temp = db.Carts.Where(u => u.PId.Equals(pId) && u.UserId.Equals(uid) && u.IsActive == true);
                if (temp.Count() == 0)
                {
                    db.Carts.Add(c);
                    db.SaveChanges();
                }
                return(RedirectToAction("Cart", "Account"));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Exemple #4
0
        public ActionResult DeleteProduct()
        {
            int pId = Convert.ToInt32(Request.Form["dpid"]);

            var db = new FootWearDb();
            var m  = db.Products.Where(u => u.PId.Equals(pId)).FirstOrDefault();

            db.Products.Remove(m);
            db.SaveChanges();

            if ((Request.Form["mpid"]) == "Index")
            {
                return(RedirectToAction("Index", "AdminHome"));
            }
            else if ((Request.Form["mpid"]) == "Kids")
            {
                return(RedirectToAction("Kids", "AdminHome"));
            }
            else if ((Request.Form["mpid"]) == "Men")
            {
                return(RedirectToAction("Men", "AdminHome"));
            }
            else
            {
                return(RedirectToAction("Women", "AdminHome"));
            }
        }
Exemple #5
0
        public ActionResult InsertProduct(Product model)
        {
            model.PImage = "/Images/" + Request.Form["pic"];
            var FootDB = new FootWearDb();

            FootDB.Products.Add(model);
            FootDB.SaveChanges();
            return(RedirectToAction("Index", "AdminHome"));
        }
Exemple #6
0
        public ActionResult RemoveCart()
        {
            int  uid  = WebSecurity.GetUserId(User.Identity.Name);
            int  pId  = Convert.ToInt32(Request.Form["pid"]);
            var  db   = new FootWearDb();
            Cart temp = db.Carts.Where(u => u.PId.Equals(pId) && u.UserId.Equals(uid)).FirstOrDefault();

            db.Carts.Remove(temp);
            db.SaveChanges();
            return(RedirectToAction("Cart", "Account"));
        }
Exemple #7
0
        public ActionResult UpdatePerson(PersonInfo model)
        {
            model.UserId = Convert.ToInt32(Request.Form["userid"]);
            model.PIId   = Convert.ToInt32(Request.Form["pid"]);
            var db = new FootWearDb();

            db.PersonInfoes.Attach(model);
            db.Entry(model).State = System.Data.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Manage", "Account"));
        }
Exemple #8
0
        public ActionResult Update(Product model)
        {
            model.PId    = Convert.ToInt32(Request.Form["pid"]);
            model.PImage = Request.Form["pimg"];
            if (Request.Form["pic"] != "")
            {
                model.PImage = "/Images/" + Request.Form["pic"];
            }
            var db       = new FootWearDb();
            var original = db.Products.Find(model.PId);

            if (original != null)
            {
                original.PName     = model.PName;
                original.Price     = model.Price;
                original.PCategory = model.PCategory;

                original.PImage = model.PImage;

                db.SaveChanges();
            }
            return(RedirectToAction("Index", "AdminHome"));
        }