Exemplo n.º 1
0
 public ActionResult Manage([Bind(Include = "UserNameID,UserName,Password,Role,FullName,Birthday,Email,Address,Phone")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Store"));
     }
     return(View(user));
 }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "BranchID,BranchName")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                db.Branches.Add(branch);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(branch));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ProducTypeID,ProductTypeName")] ProductType producttype)
        {
            if (ModelState.IsValid)
            {
                db.ProductTypes.Add(producttype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(producttype));
        }
        public ActionResult Create([Bind(Include = "UserNameID,UserName,Password,Role,FullName,Birthday,Email,Address,Phone")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "OrderID,UserNameID,OrderDate,Total,DeliveryAddress,PhoneContact")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserNameID = new SelectList(db.Users, "UserNameID", "UserName", order.UserNameID);
            return(View(order));
        }
        public ActionResult Create([Bind(Include = "CategoryID,CategoryName,ProductTypeID")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductTypeID = new SelectList(db.ProductTypes, "ProducTypeID", "ProductTypeName", category.ProductTypeID);
            return(View(category));
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "OrderDetailID,OrderID,ProductID,Quantity,UnitPrice")] OrderDetail orderdetail)
        {
            if (ModelState.IsValid)
            {
                db.OrderDetails.Add(orderdetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "UserNameID", orderdetail.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "CategoryID", orderdetail.ProductID);
            return(View(orderdetail));
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "ProductID,CategoryID,ProductName,BranchID,Description,Price,Quantity,images")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BranchID   = new SelectList(db.Branches, "BranchID", "BranchName", product.BranchID);
            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
            return(View(product));
        }
Exemplo n.º 9
0
        public ActionResult Register(Register userInfo)
        {
            PenStoreEntities db   = new PenStoreEntities();
            bool             user = db.Users.Any(u => u.UserName == userInfo.UserName);

            if (!user)
            {
                User us    = new User();
                int  count = (from p in db.Users
                              select p).Count();
                count++;
                us.UserNameID = ("U0" + count).ToString();
                us.Role       = "EndUser";
                us.UserName   = userInfo.UserName;
                String haspas = GetMD5HashData(userInfo.Password);
                us.Password = haspas;
                us.FullName = userInfo.FullName;
                us.Birthday = userInfo.Birthday;
                us.Email    = userInfo.Email;
                us.Address  = userInfo.Address;
                us.Phone    = userInfo.Phone;
                db.Users.Add(us);
                db.SaveChanges();
                Session["UserName"] = us.UserName;
                FormsAuthentication.SetAuthCookie(us.UserName, false);
                return(RedirectToAction("Index", "Store"));
            }
            else
            {
                ViewData["Error"] = "UserName is exist";
            }
            return(View());
        }
Exemplo n.º 10
0
        //
        // GET: /ShoppingCart/AddToCart/5

        public ActionResult AddToCart(string id)
        {
            // Retrieve the album from the database
            var addedProduct = storeDB.Products
                               .Single(pro => pro.ProductID == id);

            // Add it to the shopping cart
            var cart = ShoppingCart.GetCart(storeDB, this.HttpContext);

            cart.AddToCart(addedProduct);

            storeDB.SaveChanges();

            // Go back to the main store page for more shopping
            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public ActionResult Register(Register userInfo)
        {
            PenStoreEntities db   = new PenStoreEntities();
            bool             user = db.Users.Any(u => u.UserName == userInfo.UserName);

            if (!user)
            {
                User us = new User();
                us.Role       = "EndUser";
                us.UserNameID = "U024";
                us.UserName   = userInfo.UserName;
                String haspas = GetMD5HashData(userInfo.Password);
                us.Password = haspas;
                us.FullName = userInfo.FullName;
                us.Birthday = userInfo.Birthday;
                us.Email    = userInfo.Email;
                us.Address  = userInfo.Address;
                us.Phone    = userInfo.Phone;
                db.Users.Add(us);
                db.SaveChanges();
                FormsAuthentication.SetAuthCookie(us.UserName, false);
                return(RedirectToAction("Index", "Store"));
            }
            else
            {
                ModelState.AddModelError("", "Error");
            }
            return(View());
        }
Exemplo n.º 12
0
        public ActionResult Create(User userInfo)
        {
            PenStoreEntities db   = new PenStoreEntities();
            bool             user = db.Users.Any(u => u.UserName == userInfo.UserName);

            if (!user)
            {
                User us = new User();
                us.Role       = userInfo.Role;
                us.UserNameID = userInfo.UserNameID;
                us.UserName   = userInfo.UserName;
                String haspas = GetMD5HashData(userInfo.Password);
                us.Password = haspas;
                us.FullName = userInfo.FullName;
                us.Birthday = userInfo.Birthday;
                us.Email    = userInfo.Email;
                us.Address  = userInfo.Address;
                us.Phone    = userInfo.Phone;

                db.Users.Add(us);
                db.SaveChanges();
                return(RedirectToAction("Index", "ManageUser"));
            }
            else
            {
                ViewData["Error"] = "UserName is exist";
            }
            return(View());
        }
Exemplo n.º 13
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var   PhoneContact    = values["PhoneContact"];
            var   DeliveryAddress = values["DeliveryAddress"];
            Order or = new Order();

            or.PhoneContact    = PhoneContact;
            or.DeliveryAddress = DeliveryAddress;
            string sessionname = Session["UserName"].ToString();
            var    userid      = _db.Users.SingleOrDefault(t => t.UserName == sessionname).UserNameID;

            or.UserNameID = userid;
            or.OrderDate  = DateTime.Now;
            var     cart      = ShoppingCart.GetCart(_db, this.HttpContext);
            decimal carttotal = cart.GetTotal();

            or.Total = Convert.ToDouble(carttotal);
            _db.Orders.Add(or);
            _db.SaveChanges();
            cart.CreateOrder(or);

            return(RedirectToAction("Complete",
                                    new { id = or.OrderID }));
            //var order = new Order();
            //TryUpdateModel(order);
            //string a = values["PromoCode"];



            //try
            //{
            //    if (string.Equals(values["PromoCode"], PromoCode,
            //        StringComparison.OrdinalIgnoreCase) == false)
            //    {
            //        return View(order);
            //    }
            //    else
            //    {
            //        order.Username = User.Identity.Name;
            //        order.OrderDate = DateTime.Now;

            //        //Save Order
            //        storeDB.Orders.Add(order);
            //        storeDB.SaveChanges();
            //        //Process the order
            //        var cart = ShoppingCart.GetCart(this.HttpContext);
            //        cart.CreateOrder(order);

            //        return RedirectToAction("Complete",
            //            new { id = order.OrderId });
            //    }
            //}
            //catch
            //{
            //    //Invalid - redisplay with errors
            //    return View(order);
            //}
        }