示例#1
0
        public ActionResult Create([Bind(Include = "id,email,password,fullname,phone,gender,dayOfBirth,address,avatar,idCounty,activated,status,createdDate,modifyDate,modifyBy,roleId")] Customer customer,
                                   HttpPostedFileBase avatar)
        {
            if (ModelState.IsValid)
            {
                string path = Server.MapPath("/Assets/Admin/resources/customer");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (customer.avatar != null)
                {
                    avatar.SaveAs(path + "/" + avatar.FileName);
                    customer.avatar = "Assets/Admin/resources/customer/" + avatar.FileName;
                }
                else
                {
                    customer.avatar = "Assets/Admin/resources/customer/" + "customerDefault.jpg";
                }

                customer.createdDate = DateTime.Now;
                customer.password    = EncryptPassword.EncryptForPassword(customer.password);
                db.Customers.Add(customer);
                db.SaveChanges();
                return(new RedirectResult(url: "/Admin/Customers/Index?message=insert_success"));
            }

            ViewBag.idCounty = new SelectList(db.Counties, "id", "name", customer.idCounty);
            ViewBag.roleId   = new SelectList(db.Roles, "id", "name", customer.roleId);
            return(View(customer));
        }
        public ActionResult Edit([Bind(Include = "id,email,password,fullname,phone,gender,dayOfBirth,address,avatar,dateStart,dateEnd,contractSalary,unitSalary,workTime,schedule,createdDate,createdBy,modifyDate,modifyBy,status,activated")] Employee employee,
                                 HttpPostedFileBase avatar, string role)
        {
            if (ModelState.IsValid)
            {
                string path = Server.MapPath("/Assets/Admin/resources/image");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (employee.avatar != null)
                {
                    avatar.SaveAs(path + "/" + avatar.FileName);
                    employee.avatar = "Assets/Admin/resources/image/" + avatar.FileName;
                }
                else
                {
                    employee.avatar = "Assets/Admin/resources/image/" + "userDefault.jpg";
                }

                AccountRole account = new AccountRole();
                account.employeeId  = employee.id;
                account.roleId      = Convert.ToInt32(role);
                employee.modifyDate = DateTime.Now;
                employee.modifyBy   = Session["username_Employee"].ToString();
                employee.password   = EncryptPassword.EncryptForPassword(employee.password);
                db.AccountRoles.Add(account);
                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(new RedirectResult(url: "/Admin/Employees/Index?message=update_success"));
            }
            return(View(employee));
        }
 public ActionResult Login(string email, string password)
 {
     if (email != null && password != null)
     {
         using (LAUNDRY_PROJECTEntities db = new LAUNDRY_PROJECTEntities())
         {
             var account = db.Employees.Where(x => x.email.Equals(email)).SingleOrDefault();
             if (account != null)
             {
                 var passwordCheck = account.password.Equals(EncryptPassword.EncryptForPassword(password));
                 if (passwordCheck)
                 {
                     Session["username_Employee"] = account.fullname;
                     Session["email_Employee"]    = account.email;
                     Session["password_Employee"] = EncryptPassword.DecryptPassword(account.password);
                     Session["id_Employee"]       = account.id;
                     Session["image_Employee"]    = account.avatar;
                     FormsAuthentication.SetAuthCookie(email, false);
                     return(RedirectToAction("Index", "DashBoard"));
                 }
                 else
                 {
                     return(new RedirectResult(url: "/Admin/Account/Login?message=invalid_password"));
                 }
             }
             else
             {
                 return(new RedirectResult(url: "/Admin/Account/Login?message=invalid_email"));
             }
         }
     }
     return(RedirectToAction("Index", "DashBoard"));
 }
        public JsonResult changePassword(long id, string newPass)
        {
            LAUNDRY_PROJECTEntities db = new LAUNDRY_PROJECTEntities();
            Employee employee          = db.Employees.Where(x => x.id == id).FirstOrDefault();

            employee.password = EncryptPassword.EncryptForPassword(newPass);
            db.SaveChanges();
            return(Json(1, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create([Bind(Include = "id,email,password,fullname,phone,gender,dayOfBirth,address,avatar,dateStart,dateEnd,contractSalary,unitSalary,workTime,schedule,createdDate,createdBy,modifyDate,modifyBy,status,activated")] Employee employee,
                                   HttpPostedFileBase avatar, string role)
        {
            if (ModelState.IsValid)
            {
                var checkEmail = db.Employees.Where(x => x.email.Equals(employee.email)).FirstOrDefault();
                if (checkEmail == null)
                {
                    string path = Server.MapPath("/Assets/Admin/resources/image");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    if (employee.avatar != null)
                    {
                        avatar.SaveAs(path + "/" + avatar.FileName);
                        employee.avatar = "Assets/Admin/resources/image/" + avatar.FileName;
                    }
                    else
                    {
                        employee.avatar = "Assets/Admin/resources/image/" + "userDefault.jpg";
                    }
                    AccountRole account = new AccountRole();
                    account.employeeId   = employee.id;
                    account.roleId       = Convert.ToInt32(role);
                    employee.createdDate = DateTime.Now;
                    employee.dateEnd     = DateTime.Now.AddYears(1);
                    employee.createdBy   = Session["username_Employee"].ToString();
                    employee.status      = true;
                    employee.activated   = false;
                    employee.password    = EncryptPassword.EncryptForPassword(employee.password);

                    db.AccountRoles.Add(account);
                    db.Employees.Add(employee);
                    db.SaveChanges();

                    SendEmail.SendMail("Gửi từ Laundry Store, Xác nhận người dùng ! ", employee.email, " Bạn vừa đăng kí thành công tài khoản tại Laundry Store !" +
                                       " Với tên đăng nhập : " + employee.email +
                                       " Để kích hoạt tài khoản vừa đăng kí, vui lòng xác nhận tại đường dẫn tại đây: " + "https://localhost:44335/Admin/Employees/ActiveEmail?username="******"/Admin/Employees/Index?message=confirm_email"));
                }
                else
                {
                    return(new RedirectResult(url: "/Admin/Employees/Index?message=email_exists"));
                }
            }
            return(View(employee));
        }
示例#6
0
        public ActionResult RegisterAccount(FormCollection form)
        {
            LAUNDRY_PROJECTEntities db = new LAUNDRY_PROJECTEntities();
            string email           = Request.Form["email"];
            string password        = Request.Form["password"];
            string confirmPassword = Request.Form["confirmPassword"];

            var checkEmail = db.Customers.Where(c => c.email.Equals(email)).FirstOrDefault();

            if (checkEmail != null)
            {
                return(new RedirectResult(url: "/Account/RegisterAccount?message=email_exists"));
            }
            else
            {
                if (!password.Equals(confirmPassword))
                {
                    return(new RedirectResult(url: "/Account/RegisterAccount?message=invalid_password"));
                }
                else
                {
                    Customer customer = new Customer();
                    customer.email       = email;
                    customer.password    = EncryptPassword.EncryptForPassword(password);
                    customer.fullname    = "";
                    customer.address     = "";
                    customer.idCounty    = 1;
                    customer.avatar      = "Assets/Client/resources/image/" + "customerDefault.jpg";
                    customer.activated   = false;
                    customer.status      = true;
                    customer.createdDate = DateTime.Now;
                    customer.modifyDate  = DateTime.Now;
                    customer.dayOfBirth  = DateTime.Now;
                    customer.modifyBy    = "";
                    customer.roleId      = 3;

                    db.Customers.Add(customer);
                    db.SaveChanges();

                    SendEmail.SendMail("Gửi từ Laundry Store, Xác nhận người dùng ! ", customer.email, " Bạn vừa đăng kí thành công tài khoản tại Laundry Store !" +
                                       " Với tên đăng nhập : " + customer.email +
                                       " Để kích hoạt tài khoản vừa đăng kí, vui lòng xác nhận tại đường dẫn tại đây: " + "https://localhost:44335/Account/ActiveEmail/?username="******"/Account/RegisterAccount?message=confirm_email"));
                }
            }
        }
示例#7
0
        public ActionResult LoginToComment(string email, string password)
        {
            string idPost = Request.Form["idPost"];

            if (email != null && password != null)
            {
                using (LAUNDRY_PROJECTEntities db = new LAUNDRY_PROJECTEntities())
                {
                    var account = db.Customers.Where(x => x.email.Equals(email) && x.status == true && x.activated == true).FirstOrDefault();
                    if (account != null)
                    {
                        if (account.activated == true)
                        {
                            var passwordCheck = account.password.Equals(EncryptPassword.EncryptForPassword(password));
                            if (passwordCheck)
                            {
                                Session["username_Customer"] = account.fullname;
                                Session["email_Customer"]    = account.email;
                                Session["password_Customer"] = account.password;
                                Session["id_Customer"]       = account.id;
                                Session["image_Customer"]    = account.avatar;
                                FormsAuthentication.SetAuthCookie(email, false);
                                return(new RedirectResult(url: "/Blogs/Details/" + idPost + "?message=login_sucess"));
                            }
                            else
                            {
                                return(new RedirectResult(url: "/Blogs/Details/" + idPost + "?message=invalid_password"));
                            }
                        }
                        else
                        {
                            return(new RedirectResult(url: "/Blogs/Details/" + idPost + "?message=authentication_email"));
                        }
                    }
                    else
                    {
                        return(new RedirectResult(url: "/Blogs/Details/" + idPost + "?message=invalid_email"));
                    }
                }
            }
            return(new RedirectResult(url: "/Blogs/Details/" + idPost));
        }
示例#8
0
 public ActionResult Login(string email, string password)
 {
     if (email != null && password != null)
     {
         using (LAUNDRY_PROJECTEntities db = new LAUNDRY_PROJECTEntities())
         {
             var account = db.Customers.Where(x => x.email.Equals(email) && x.status == true && x.activated == true).FirstOrDefault();
             if (account != null)
             {
                 if (account.activated == true)
                 {
                     var passwordCheck = account.password.Equals(EncryptPassword.EncryptForPassword(password));
                     if (passwordCheck)
                     {
                         Session["username_Customer"] = account.fullname;
                         Session["email_Customer"]    = account.email;
                         Session["password_Customer"] = EncryptPassword.DecryptPassword(account.password);
                         Session["id_Customer"]       = account.id;
                         Session["image_Customer"]    = account.avatar;
                         FormsAuthentication.SetAuthCookie(email, false);
                         return(RedirectToAction("Index", "Home"));
                     }
                     else
                     {
                         return(new RedirectResult(url: "/Account/Login?message=invalid_password"));
                     }
                 }
                 else
                 {
                     return(new RedirectResult(url: "/Account/Login?message=authentication_email"));
                 }
             }
             else
             {
                 return(new RedirectResult(url: "/Account/Login?message=invalid_email"));
             }
         }
     }
     return(View());
 }
        public ActionResult Contact(FormCollection form)
        {
            string first_name = Request.Form["first_name"];
            string last_name  = Request.Form["last_name"];
            string fullname   = null;

            if (first_name != null && last_name != null)
            {
                fullname = first_name + last_name;
            }
            string email       = Request.Form["email"];
            string phone       = Request.Form["phone"];
            string service     = Request.Form["service"];
            string description = Request.Form["description"];

            //khach hang khong dang nhap. tao tai khoan cho khach hang nhu email va ten ma khach hang nhap vao
            //mat khau tao mac dinh la sdt cua khach hang dang nhap vao va minh tu kich hoat tai khoan cho no luon
            Customer customer = new Customer();

            if (Session["id_Customer"] == null)
            {
                var account = db.Customers.Where(x => x.email.Equals(email)).FirstOrDefault();
                if (account != null)
                {
                    return(new RedirectResult(url: "/Home/Contact?message=invalid_email"));
                }
                customer.email       = email;
                customer.password    = EncryptPassword.EncryptForPassword(phone);
                customer.fullname    = fullname.ToString();
                customer.phone       = Convert.ToInt32(phone);
                customer.address     = "";
                customer.idCounty    = 1;
                customer.avatar      = "Assets/Client/resources/image/" + "customerDefault.jpg";
                customer.activated   = true;
                customer.status      = true;
                customer.createdDate = DateTime.Now;
                customer.modifyDate  = DateTime.Now;
                customer.modifyBy    = fullname.ToString();
                customer.dayOfBirth  = DateTime.Now;
                customer.roleId      = 3;

                db.Customers.Add(customer);
                db.SaveChanges();

                SendEmail.SendMail("Gửi từ Laundry Store, Xác nhận người dùng ! ", customer.email, " Bạn vừa đăng kí thành công tài khoản tại Laundry Store !" +
                                   " Với tên đăng nhập : " + customer.email +
                                   " Bạn có thể sử dụng email trên để đăng nhập vào cửa hàng của chúng tôi với mật khẩu là số điện thoại của bạn : " + customer.phone + " " +
                                   " Vui lòng truy cập vào đường dẫn dưới đây để cập nhật thông tin tài khoản " + "https://localhost:44335/Account/infoProfile/" + customer.id);
            }
            //khach hang co dang nhap tai khoan
            else
            {
                var customerId = int.Parse(Session["id_Customer"].ToString());
                customer = db.Customers.Find(customerId);
                if (customer != null)
                {
                    customer.email      = Session["email_Customer"].ToString();
                    customer.fullname   = Session["username_Customer"].ToString();
                    customer.modifyDate = DateTime.Now;
                    customer.modifyBy   = Session["username_Customer"].ToString();
                    db.SaveChanges();
                }
            }

            Order order = new Order();

            order.customerId    = customer.id;
            order.orderDate     = DateTime.Now;
            order.paymentStatus = "doing";
            order.description   = description;
            order.statusId      = 2;
            order.createdBy     = customer.fullname;
            order.status        = true;
            db.Orders.Add(order);
            db.SaveChanges();

            //insert table barcodes
            Barcode barcode = new Barcode();

            barcode.orderId     = order.id;
            barcode.codeName    = RandomBarCodes.RandomBarCode();
            barcode.createdDate = DateTime.Now;
            barcode.createdBy   = fullname.ToString();
            db.Barcodes.Add(barcode);
            db.SaveChanges();

            OrderDetail orderDetail = new OrderDetail();

            orderDetail.orderId   = order.id;
            orderDetail.productId = Convert.ToInt32(service);
            orderDetail.status    = true;

            db.OrderDetails.Add(orderDetail);
            db.SaveChanges();
            return(new RedirectResult(url: "/Home/Contact?message=contactSuccess"));
        }
示例#10
0
        public ActionResult CreateMessage(FormCollection form)
        {
            string name            = Request.Form["name"];
            string email           = Request.Form["email"];
            string message         = Request.Form["message"];
            string idPost          = Request.Form["idPost"];
            string passwordDefault = "laundry1234";

            //khach hang khong dang nhap. tao tai khoan cho khach hang nhu email va ten ma khach hang nhap vao
            Customer customer = new Customer();

            if (Session["id_Customer"] == null)
            {
                var account = db.Customers.Where(x => x.email.Equals(email)).FirstOrDefault();
                if (account != null)
                {
                    return(new RedirectResult(url: "/Blogs/Details/" + idPost + "?message=invalid_email"));
                }
                customer.email       = email;
                customer.password    = EncryptPassword.EncryptForPassword(passwordDefault);
                customer.fullname    = name;
                customer.address     = "";
                customer.idCounty    = 1;
                customer.avatar      = "Assets/Client/resources/image/" + "customerDefault.jpg";
                customer.activated   = true;
                customer.status      = true;
                customer.createdDate = DateTime.Now;
                customer.modifyDate  = DateTime.Now;
                customer.modifyBy    = name;
                customer.dayOfBirth  = DateTime.Now;
                customer.roleId      = 3;

                db.Customers.Add(customer);
                db.SaveChanges();

                string password = EncryptPassword.DecryptPassword(customer.password);

                SendEmail.SendMail("Gửi từ Laundry Store, Xác nhận người dùng ! ", customer.email, " Bạn vừa đăng kí thành công tài khoản tại Laundry Store !" +
                                   " Với tên đăng nhập : " + customer.email +
                                   " Bạn có thể sử dụng email trên để đăng nhập vào cửa hàng của chúng tôi với mật khẩu mặc định là : " + password + " " +
                                   " Vui lòng truy cập vào đường dẫn dưới đây để cập nhật thông tin tài khoản " + "https://localhost:44335/Account/infoProfile/" + customer.id);
            }
            //khach hang co dang nhap tai khoan
            else
            {
                var customerId = int.Parse(Session["id_Customer"].ToString());
                customer = db.Customers.Find(customerId);
                if (customer != null)
                {
                    customer.email      = Session["email_Customer"].ToString();
                    customer.fullname   = Session["username_Customer"].ToString();
                    customer.modifyDate = DateTime.Now;
                    customer.modifyBy   = Session["username_Customer"].ToString();
                    db.SaveChanges();
                }
            }

            Comment comment = new Comment();

            comment.content     = message;
            comment.customerId  = customer.id;
            comment.newId       = Convert.ToInt32(idPost);
            comment.createdDate = DateTime.Now;
            comment.createdBy   = customer.fullname;
            comment.modifyDate  = DateTime.Now;
            comment.modifyBy    = customer.fullname;
            comment.status      = true;
            db.Comments.Add(comment);
            db.SaveChanges();
            return(new RedirectResult(url: "/Blogs/Details/" + idPost + "?message=comment"));
        }
示例#11
0
        public JsonResult purchase(string fullName, string email, int phone, string county, string address, string description)
        {
            //khach hang khong dang nhap
            Customer customer = new Customer();

            if (Session["id_Customer"] == null)
            {
                customer.email       = email;
                customer.password    = EncryptPassword.EncryptForPassword(phone.ToString());
                customer.fullname    = fullName;
                customer.phone       = phone;
                customer.address     = address;
                customer.avatar      = "Assets/Client/resources/image/" + "customerDefault.jpg";
                customer.idCounty    = Int32.Parse(county);
                customer.activated   = true;
                customer.status      = true;
                customer.createdDate = DateTime.Now;
                customer.modifyDate  = DateTime.Now;
                customer.modifyBy    = fullName;
                customer.dayOfBirth  = DateTime.Now;
                customer.roleId      = 3;

                db.Customers.Add(customer);
                db.SaveChanges();

                SendEmail.SendMail("Gửi từ Laundry Store, Xác nhận người dùng ! ", customer.email, " Bạn vừa đăng kí thành công tài khoản tại Laundry Store !" +
                                   " Với tên đăng nhập : " + customer.email +
                                   " Bạn có thể sử dụng email trên để đăng nhập vào cửa hàng của chúng tôi với mật khẩu là số điện thoại của bạn : " + customer.phone + " " +
                                   " Vui lòng truy cập vào đường dẫn dưới đây để cập nhật thông tin tài khoản " + "https://localhost:44335/Account/infoProfile/" + customer.id);
            }
            else
            {
                var customerId = int.Parse(Session["id_Customer"].ToString());
                customer = db.Customers.Find(customerId);
                if (customer != null)
                {
                    customer.email      = email;
                    customer.fullname   = fullName;
                    customer.phone      = phone;
                    customer.address    = address;
                    customer.idCounty   = Int32.Parse(county);
                    customer.modifyDate = DateTime.Now;
                    customer.modifyBy   = Session["username_Customer"].ToString();
                    db.SaveChanges();
                }
            }

            //them don hang vao trong order
            Order order = new Order();

            order.customerId      = customer.id;
            order.orderDate       = DateTime.Now;
            order.address         = address;
            order.paymentMethodId = 1;
            order.paymentStatus   = "doing";
            order.amount          = totalQuantity();
            order.description     = description;
            order.statusId        = 2;
            order.createdBy       = customer.fullname;
            order.shippingId      = 1;
            order.totalDebt       = 0;
            order.status          = true;
            double?total = totalMoney();

            order.totalOrder = Convert.ToInt64(total);
            db.Orders.Add(order);
            db.SaveChanges();

            //insert table barcodes
            Barcode barcode = new Barcode();

            barcode.orderId     = order.id;
            barcode.codeName    = RandomBarCodes.RandomBarCode();
            barcode.createdDate = DateTime.Now;
            barcode.createdBy   = fullName;
            db.Barcodes.Add(barcode);
            db.SaveChanges();

            //them don hang vao chi tiet don hang
            List <CartItem> listCart = getCart();

            foreach (CartItem item in listCart)
            {
                OrderDetail orderDetail = new OrderDetail();
                orderDetail.orderId    = order.id;
                orderDetail.productId  = Convert.ToInt32(item.productId);
                orderDetail.discount   = item.discount;
                orderDetail.price      = item.price;
                orderDetail.type       = item.type;
                orderDetail.status     = true;
                orderDetail.totalPrice = Convert.ToInt64(item.total);
                db.OrderDetails.Add(orderDetail);
                db.SaveChanges();
            }

            Session["cart"] = null;
            if (Session["id_Customer"] == null)
            {
                return(Json(1, JsonRequestBehavior.AllowGet));
            }
            return(Json(2, JsonRequestBehavior.AllowGet));
        }