Ejemplo n.º 1
0
        public ActionResult Signup(FormCollection Field)
        {
            if (Field["Password"] != Field["uRepass"])
            {
                return(View());
            }
            Users user = new Users();

            user.Username = Field["Username"];
            user.Password = Field["Password"];
            user.nickname = Field["nickname"];
            user.email    = Field["email"];
            if (Field["type"] == "User")
            {
                user.Role = "2";
            }
            else if (Field["type"] == "Seller")
            {
                user.Role = "1";
            }
            else
            {
                return(View());
            }
            _db.Users.Add(user);
            _db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            User user = db.Users.Where(s => s.idUser == id).FirstOrDefault();

            db.Users.Remove(user);
            db.SaveChanges();
            return(RedirectToAction("UserIndex", "Admin"));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName,UnitPrice,ProductDate,Available,Category,Description")] Product product, HttpPostedFileBase image)
        {
            if (image != null && image.ContentLength > 0)
            {
                product.Image = new byte[image.ContentLength]; // image stored in binary formate
                image.InputStream.Read(product.Image, 0, image.ContentLength);
                string fileName = System.IO.Path.GetFileName(image.FileName);
                string urlImage = Server.MapPath("~/Image/" + fileName);
                image.SaveAs(urlImage);

                product.UrlImage = "Image/" + fileName;
            }
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Ejemplo n.º 4
0
 public ActionResult addProduct(FormCollection Fields, Product model)
 {
     if (ModelState.IsValid)
     {
         ModelState.AddModelError("", "Upload Product Complete");
         Seller.Models.Product Product = new Models.Product();
         Product.pID      = Fields["pID"];
         Product.pName    = Fields["pName"];
         Product.pGia     = Int32.Parse(Fields["pGia"]);
         Product.pSoLuong = Int32.Parse(Fields["pSoLuong"]);
         Product.pURL     = Fields["pImg"];
         _db.Product.Add(Product);
         _db.SaveChanges();
         return(View("addProduct"));
     }
     return(View());
 }
Ejemplo n.º 5
0
        public ActionResult ChangePass(string pass, string newpass1, string newpass2)
        {
            if (ModelState.IsValid)
            {
                if (newpass1 == newpass2)
                {
                    string uname = Session["Username"].ToString();

                    var    _db = db.Users.Where(s => s.Password == pass && s.Username == uname).ToList();
                    string sms = "";
                    if (_db.Count > 0)
                    {
                        string      email   = _db.FirstOrDefault().Email;
                        Random      rd      = new Random();
                        int         code    = rd.Next(100000, 999999);
                        CodeAndInfo newCode = new CodeAndInfo()
                        {
                            level    = 0, // bang 0 doi mat khau
                            newPass  = newpass1,
                            code     = code,
                            newBirth = DateTime.Now,
                        };
                        db.codeAndInfos.Add(newCode);
                        db.SaveChanges();
                        sms += "Chào " + uname + ". Mã xác thực của bạn là: ";
                        MailMessage mail   = new MailMessage("*****@*****.**", email, sms, code.ToString());
                        SmtpClient  client = new SmtpClient("smtp.gmail.com", 587);
                        client.EnableSsl   = true;
                        client.Credentials = new NetworkCredential("*****@*****.**", "13122802");
                        mail.IsBodyHtml    = true;
                        client.Send(mail);
                        ViewBag.suc = "Get Success! Check your mail";
                    }
                    else if (_db.Count == 0)
                    {
                        // ModelState.AddModelError("Invalid", "Username or password not exits");
                        return(View("ChangePass"));
                    }
                    return(View("ConfirmCode"));
                }
            }
            //ModelState.Clear();
            return(View());
        }
Ejemplo n.º 6
0
 public ActionResult Register(User _user)
 {
     if (ModelState.IsValid)
     {
         var check = _db.Users.FirstOrDefault(s => s.Username == _user.Username);
         if (check == null)
         {
             _user.Password = GetMD5(_user.Password);
             _db.Configuration.ValidateOnSaveEnabled = false;
             _db.Users.Add(_user);
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewBag.error = "Username already exists";
             return(View());
         }
     }
     return(View());
 }
Ejemplo n.º 7
0
 public ActionResult SignUp(FormCollection fields)
 {
     if (fields["Password"] != fields["PasswordAgain"])
     {
         return(View());
     }
     using (LTWebEntities _db = new LTWebEntities())
     {
         User a = new User();
         a.Username = fields["Username"];
         a.Email    = fields["gmail"];
         a.Password = fields["Password"];
         a.Phone    = int.Parse(fields["numberPhone"]);
         a.Lever    = 3;
         a.HoTen    = "";
         a.DiaChi   = "";
         a.ngaySinh = DateTime.Now;
         _db.Users.Add(a);
         _db.SaveChanges();
     }
     return(View());
 }
Ejemplo n.º 8
0
        // oder sản phẩm từ giỏ hàng // gửi mail
        public ActionResult Order()
        {
            if (Session["Username"] == null)
            {
                return(RedirectToAction("SignIn", "Login"));
            }

            int idcart;

            try
            {
                idcart = db.Carts.Select(s => s.IDCart).Max() + 1;
            }
            catch
            {
                idcart = 1;
            }
            string      username = Session["Username"].ToString().Trim();
            int         iduser   = db.Users.Where(s => s.Username.Trim() == username).Select(s => s.idUser).FirstOrDefault();
            List <Cart> giohang  = Session["giohang"] as List <Cart>;

            foreach (Cart oItem in giohang)
            {
                oItem.IDCart = idcart;
                oItem.IDuser = iduser;
                db.Carts.Add(oItem);
                db.SaveChanges();
            }
            var gia     = db.Carts.Where(s => s.IDCart == idcart).Sum(s => s.Price);
            var stt     = db.Carts.Where(s => s.IDCart == idcart).Select(s => s.Status).FirstOrDefault();
            var newCart = new ListCart()
            {
                IDCart     = idcart,
                TotalPrice = gia,
                IDuser     = iduser,
                Status     = stt.Trim(),
                ngayBan    = DateTime.Now,
            };

            db.listCarts.Add(newCart);
            db.SaveChanges();
            return(RedirectToAction("GetPaging"));

            #region ai biet gi
            //string Sms = "<htmt><body><table border='1'><caption> Thông tin đặt hàng</caption><tr><th> STT </th><th> Tên Sản Phẩm </th><th> Số lượng </th> <th> Đơn giá </th> <th> Thành tiền</th></tr>";
            //int i = 0;
            //double tongtien = 0;
            //foreach (Cart item in giohang)
            //{
            //    i++;
            //    Sms += "<tr>";
            //    Sms += "<td>" + i.ToString() + "</td>";
            //    Sms += "<td>" + item.ProductName + "</td>";
            //    Sms += "<td>" + item.Status + "</td>";
            //    Sms += "<td>" + item.Price + "</td>";
            //    Sms += "<td>" + string.Format("{0:#,###}", item.Amount * item.Price) + "</td>";
            //    Sms += "</tr>";
            //    tongtien += item.Amount * item.Price;

            //}
            //if (Email == null || Email == "")
            //{
            //    ViewBag.Er = "vui lòng nhập Email đặt hàng";

            //}
            //else
            //{

            //    Sms += "<tr><th colspan='5'> Tổng cộng: " + string.Format("{0:#,### vnđ}", tongtien) + "</th> </tr> </table>";
            //    MailMessage mail = new MailMessage("*****@*****.**", Email, "Thông tin đơn hàng", Sms);
            //    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            //    client.EnableSsl = true;
            //    client.Credentials = new NetworkCredential("*****@*****.**", "vinhduc147a");
            //    mail.IsBodyHtml = true;
            //    client.Send(mail);
            //}
            #endregion
        }