Exemple #1
0
 public bool Delete(int id)
 {
     try
     {
         db.Carts.Remove(db.Carts.Find(id));
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #2
0
        public ActionResult ThayDoiMatKhau()
        {
            var  passChange = Request.Cookies["passChange"].Value.ToString();
            var  userId     = Session["idUser"].ToString();
            User userLogin  = new User();

            userLogin          = db.Users.Where(u => u.UserID.ToString() == userId).FirstOrDefault();
            userLogin.Password = md5(passChange);
            db.SaveChanges();
            return(RedirectToAction("Index", "Login"));
        }
Exemple #3
0
        public ActionResult Index(Register register)
        {
            Customer cus = new Customer();

            cus.Fullname    = register.FullName;
            cus.PhoneNumber = register.PhoneNumber;
            db.Customers.Add(cus);
            db.SaveChanges();
            User userLogin = new User();

            userLogin.Username = register.UserName;
            userLogin.Password = md5(register.PassWord);
            var userFilter = db.Customers.Where(u => u.PhoneNumber == register.PhoneNumber).FirstOrDefault();

            if (userFilter != null)
            {
                userLogin.UserID = userFilter.Id;
            }
            db.Users.Add(userLogin);
            db.SaveChanges();
            return(RedirectToAction("Index", "Login"));
        }
Exemple #4
0
        public ActionResult CreateNewProduct([Bind(Include = "productID, productName, productPrice, productSale, productInfor, productIntroduce, TypeID, Status")] Product product, HttpPostedFileBase image)
        {
            QL_Hang db = new QL_Hang();

            if (image != null && image.ContentLength > 0)
            {
                product.productImage = image.ContentLength.ToString();
                byte[] data     = Encoding.Unicode.GetBytes(product.productImage);
                string fileName = System.IO.Path.GetFileName(image.FileName);
                string urlImage = Server.MapPath("~/Content/Images/" + fileName);
                image.SaveAs(urlImage);
                product.productImage = fileName;
            }

            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
Exemple #5
0
        public ActionResult Register(User user)
        {
            QL_Hang db = new QL_Hang();

            if (ModelState.IsValid)
            {
                var check = db.Users.FirstOrDefault(s => s.Email == user.Email);
                if (check == null)
                {
                    user.Password = MD5Hash(user.Password);
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.Users.Add(user);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "AdminPage"));
                }
                else
                {
                    ViewBag.error = "Email already exists";
                    return(View());
                }
            }
            return(View());
        }
Exemple #6
0
 public int Insert(Order order)
 {
     db.Orders.Add(order);
     db.SaveChanges();
     return(order.cartID);
 }
Exemple #7
0
 public void Add(Product product)
 {
     db.Products.Add(product);
     db.SaveChanges();
 }
Exemple #8
0
 public void Create(Category category)
 {
     db.Categories.Add(category);
     db.SaveChanges();
 }