public bool Register(Account account)
        {
            account.CreatedDate = DateTime.Now;
            account.UpdatedDate = DateTime.Now;
            account.Status = EntityStatuses.Actived.ToString();
            AccountService service = new AccountService();
            try
            {

                Accounts.InsertOnSubmit(account);
                Commit();
                return account.Id>0;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
 public ActionResult List(int page, int rows, string sidx, string sord, string Position)
 {
     var bann = new AccountService().List();
     bool searchOn = bool.Parse(Request.Form["_search"]);
     string searchExp = "";
     if (searchOn)
     {
         searchExp = string.Format("{0}.ToString().Contains(@0)", getFormValue("searchField"));
         bann = bann.Where(searchExp, new string[] { getFormValue("searchString") });
     }
     var model = from entity in bann.OrderBy(sidx + " " + sord)
                 select new
                 {
                     Id = entity.Id,
                     Name = entity.Name,
                     CreatedDate = entity.CreatedDate.ToShortDateString(),
                     Login = entity.Login,
                     Address = entity.Address,
                     Career = entity.Career.Name,
                     Sex = entity.IsMale?"Nam": "Nữ",
                     Birthday = entity.Birthday.Value.ToShortDateString(),
                     Status = entity.Status,
                     Email = entity.Email
                 };
     return Json(model.ToJqGridData(page, rows, null, "", new[] { "Name", "Login", "Address", "Status", "Career" }), JsonRequestBehavior.AllowGet);
 }
        public ActionResult Register([Bind(Exclude = "Id")]Account account, string PasswordConfirm, bool captchaValid)
        {
            if (!captchaValid)
            {
                ModelState.AddModelError("Captcha", "Mã xác nhận không hợp lệ, vui lòng nhập lại");
            }
            if (account.Password != PasswordConfirm)
            {
                ModelState.AddModelError("PasswordConfirm", "Mật khẩu xác nhận không trùng khớp");
            }

            Account test = new AccountService().GetItem(a => a.Email == account.Email || a.Login == account.Login);
            if (test != null)
            {
                ModelState.AddModelError("FORM_ERR", "Email hoặc tên đăng nhập đã có người đăng ký. vui lòng chọn tên khác.");
            }
            if (ModelState.IsValid)
            {
                account.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(account.Password, "MD5");
                //account.Career = new CareerService().GetItem(CareerId);
                bool result = (new AccountService()).Register(account);
               return RedirectToAction("Confirmation");
            }

            // If we got this far, something failed, redisplay form
            return View();
        }
        public ActionResult Login(string Login, string Password, bool captchaValid)
        {
            if (!captchaValid)
            {
                ModelState.AddModelError("Captcha", "Bạn nhập sai mã số xác nhận. ");
                return View();
            }
            if (ModelState.IsValid)
            {
                try
                {
                    Account account = new AccountService().Authenticate(Login, FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "MD5"));
                    if (account != null)
                    {
                        SessionManager.Account = account;
                        FormsAuthentication.SetAuthCookie(Login, true);
                        FormsAuthentication.RedirectFromLoginPage(Login, true);
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("System", "Sai tên đăng nhập hoặc mật khẩu không đúng. ");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("System", "Không thể thực hiện thao tác này vào lúc này. ");
                }
            }

            return View();
        }