Example #1
0
        public ActionResult Register(TaiKhoanDAO user, string rePass, string GioiTinh)
        {
            bool check = true;

            try
            {
                if (string.IsNullOrEmpty(user.TenTaiKhoan) || string.IsNullOrEmpty(user.MatKhau) || string.IsNullOrEmpty(user.SDT) || string.IsNullOrEmpty(user.DiaChi))
                {
                    ViewBag.error = "Vui lòng nhập đầy đủ thông tin";
                    return(View(user));
                }

                if (!user.MatKhau.Equals(rePass))
                {
                    ViewBag.error = "Mật khẩu không khớp. Vui lòng thử lại";
                    return(View(user));
                }
                if (GioiTinh != null)
                {
                    user.GioiTinh = true;
                }
                else
                {
                    user.GioiTinh = false;
                }
                check = TaiKhoan_Service.Insert(user);
            } catch (Exception e)
            {
                ViewBag.error = e.Message;
                return(View(user));
            }

            return(RedirectToAction("Login", "Auth"));
        }
Example #2
0
        public JsonResult addOrUpdateUsers(TaiKhoanDAO obj, bool isUpdate)
        {
            AjaxResultModel Result = new AjaxResultModel();

            bool check = true;

            try
            {
                TaiKhoanDAO user = ((TaiKhoanDAO)HttpContext.Session["User"]);
                if (obj.QuyenHan.Equals(0))
                {
                    Result.Code    = 2;
                    Result.Message = "Bạn không thể tạo tài khoản với quyền hạn admin";
                    return(Json(new JsonResult()
                    {
                        Data = Result
                    }));
                }
                if (isUpdate)
                {
                    check = TaiKhoan_Service.Update(obj);
                }
                else
                {
                    check = TaiKhoan_Service.Insert(obj);
                }
                if (check)
                {
                    Result.Code    = 0;
                    Result.Message = "Thành công";
                }
                else
                {
                    Result.Code    = 1;
                    Result.Message = "Đã có lỗi xảy ra. Vui lòng thử lại.";
                }
            }
            catch (Exception e)
            {
                Result.Code    = 999;
                Result.Message = e.Message;
                //throw;
            }
            return(Json(new JsonResult()
            {
                Data = Result
            }));
        }
Example #3
0
        public ActionResult Login(string username, string password, string remember, string url)
        {
            TaiKhoanDAO user = new TaiKhoanDAO();

            try
            {
                if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
                {
                    ViewBag.error = "Vui lòng nhập đầy đủ thông tin";
                    return(View(user));
                }
                CookieHelper.set(username, password, remember == "on");
                user = TaiKhoan_Service.checkExistAcc(username, password);
                if (user == null)
                {
                    ViewBag.error = "Tài khoản không tồn tại hoặc chưa chính xác!";
                    user          = CookieHelper.checkCookie();
                    return(View(user));
                }
                else if (!user.KichHoat)
                {
                    ViewBag.error = "Tài khoản đã bị khóa hoặc chưa được kích hoạt !";
                    user          = CookieHelper.checkCookie();
                    return(View(user));
                }
                else
                {
                    Session["User"] = user;
                    if (!string.IsNullOrEmpty(url))
                    {
                        return(Redirect(url));
                    }
                }
            }catch (Exception e)
            {
                ViewBag.error = e.Message;
                user          = CookieHelper.checkCookie();
                return(View(user));
            }
            return(RedirectToAction("Index", "Home"));
        }
Example #4
0
        public PartialViewResult _DanhSach(int pageNumber = 1, int pageSize = 10, string keyText = "")
        {
            List <TaiKhoanDAO> list = new List <TaiKhoanDAO>();

            try
            {
                int quyenHan = ((TaiKhoanDAO)HttpContext.Session["User"]).QuyenHan;
                int totalEntries;
                list = TaiKhoan_Service.GetAllBy(pageNumber, pageSize, keyText, out totalEntries, quyenHan);
                ViewBag.maxNumber  = Math.Ceiling(totalEntries / (double)pageSize);
                ViewBag.pageNumber = pageNumber;
                ViewBag.pageSize   = pageSize;
                TempData["Users"]  = list;
                TempData.Keep();
            }
            catch (Exception e)
            {
                throw e;
            }
            return(PartialView(list));
        }