Esempio n. 1
0
        public ActionResult LoginIndex(tblUser tblusers, tblHistoryLogin tblhistorylogin)
        {
            string pass = EncryptandDecrypt.Encrypt(tblusers.Password);
            var    list = db.tblUsers.Where(p => p.UserName == tblusers.UserName && p.Password == pass && p.Active == true).ToList();

            if (list.Count > 0)
            {
                var userCookie = new HttpCookie("Username");

                var id       = list[0].id.ToString(CultureInfo.InvariantCulture);
                var username = list[0].UserName;
                var fullname = list[0].FullName;
                userCookie.Values["UserID"]   = id;
                userCookie.Values["FullName"] = Server.HtmlEncode(fullname.Trim());
                userCookie.Values["fullname"] = fullname;
                userCookie.Values["UserName"] = Server.UrlEncode(username.Trim());
                userCookie.Values["username"] = username;
                tblhistorylogin.FullName      = fullname;
                tblhistorylogin.Task          = "Login hệ thống";
                tblhistorylogin.idUser        = int.Parse(id);
                tblhistorylogin.DateCreate    = DateTime.Now;
                tblhistorylogin.Active        = true;
                db.tblHistoryLogins.Add(tblhistorylogin);
                db.SaveChanges();

                userCookie.Expires = DateTime.Now.AddHours(22);
                Response.Cookies.Add(userCookie); Session["Count"] = "";
                return(Redirect("/Productad/Index"));
            }
            else
            {
                ViewBag.Note = "Tài khoản của bạn nhập không đúng, kiểm tra lại tên đăng nhập hoặc mật khẩu. Có thể tài khoản bị khóa  !";
                return(View());
            }
        }
Esempio n. 2
0
        public ActionResult Create(TblUser TblUser, FormCollection collection)
        {
            string username = TblUser.UserName;
            var    kiemtra  = db.TblUser.Where(p => p.UserName == username).ToList();

            if (kiemtra.Count > 0)
            {
                ViewBag.thongbao = "<div  class=\"alert alert-info\">Tài khoản bạn đăng đã tồn tại, vui lòng nhập tên tài khoản khác !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
            }
            else
            {
                TblUser.Password   = EncryptandDecrypt.Encrypt(TblUser.Password);
                TblUser.DateCreate = DateTime.Now;
                TblUser.Gender     = int.Parse(collection["ddlGender"]);
                string IdUser = Request.Cookies["Username"].Values["UserID"];
                TblUser.IdUser = int.Parse(IdUser);
                db.TblUser.Add(TblUser);
                db.SaveChanges();
                #region [Updatehistory]
                #endregion
                if (collection["btnSave"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã thêm tài khoản thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

                    return(Redirect("/Users/Index"));
                }
                if (collection["btnSaveCreate"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã thêm tài khoản thành công, mời bạn thêm tài khoản mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                    return(Redirect("/Users/Create"));
                }
                return(Redirect("Index"));
            }
            return(View());
        }
Esempio n. 3
0
        public ActionResult Edit(tblUser tbluser, int id, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tbluser).State = EntityState.Modified;
                var    user = db.tblUsers.First(p => p.id == id);
                string pass = tbluser.Password;
                if (pass == user.Password)
                {
                    tbluser.Password = EncryptandDecrypt.Encrypt(tbluser.Password);
                }
                else
                {
                    tbluser.Password = EncryptandDecrypt.Encrypt(tbluser.Password);
                }
                tbluser.UserName   = user.UserName;
                tbluser.DateCreate = DateTime.Now;
                string idUser = Request.Cookies["Username"].Values["UserID"];
                tbluser.idUser = int.Parse(idUser);
                db.SaveChanges();
                #region [Updatehistory]
                Updatehistoty.UpdateHistory("Edit User", Request.Cookies["Username"].Values["FullName"].ToString(), Request.Cookies["Username"].Values["UserID"].ToString());
                #endregion
                if (collection["btnSave"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã sửa tài khoản thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

                    return(Redirect("/Users/Index"));
                }
                if (collection["btnSaveCreate"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã thêm tài khoản thành công, mời bạn thêm tài khoản mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                    return(Redirect("/Users/Create"));
                }
            }
            return(View(tbluser));
        }