public ActionResult CapNhat(int id) { try { // Neu la chu tai khoan hoac admin thi hien thi edit tai khoan //TaiKhoan user = this.CurrentUser; TaiKhoan user = _TaiKhoanRepository.GetTaiKhoanByID(id); TaiKhoan editor = this.CurrentUser; if (editor.MaTaiKhoan == user.MaTaiKhoan || editor.NhomNguoiDung1.TenNhom.Equals("SuperAdmin")) { RegisterViewModel Model = new RegisterViewModel(); if (null != user) { Model.MaTaiKhoan = user.MaTaiKhoan; Model.TenTaiKhoan = user.TenTaiKhoan; Model.HoTen = user.HoTen; Model.DiaChi = user.DiaChi; Model.Email = user.Email; Model.CMND = user.CMND; Model.Coquan = user.CoQuan; // Model.MatKhau = user.MatKhau; //Model.NhapLaiMatKhau = user.MatKhau; } return View(Model); } else { return View("NotAllowed"); } // return } catch (Exception) { MessageHelper.CreateMessage(MessageType.Error, "", new List<string> { "error when update user" }, HttpContext.Response); return RedirectToAction("Index", "TrangChu"); } }
public ActionResult ChiTiet(int? id) { // Authenticated try { // Neu la chu tai khoan thi hien thi edit tai khoan if (Request.IsAuthenticated) { //TaiKhoan user = this.CurrentUser; TaiKhoan user = _TaiKhoanRepository.GetTaiKhoanByID(id.GetValueOrDefault(this.CurrentUser.MaTaiKhoan)); RegisterViewModel Model = new RegisterViewModel(); if (null != user) { Model.MaTaiKhoan = user.MaTaiKhoan; Model.TenTaiKhoan = user.TenTaiKhoan; Model.HoTen = user.HoTen; Model.DiaChi = user.DiaChi; Model.Email = user.Email; Model.CMND = user.CMND; Model.Coquan = user.CoQuan; Model.MatKhau = user.MatKhau; } return View(Model); } } catch (Exception) { MessageHelper.CreateMessage(MessageType.Error, "", new List<string> { "error when display user" }, HttpContext.Response); } return RedirectToLogin(); }
public ActionResult Dangky(RegisterViewModel model) { var myCaptcha = Request.Form["myCaptcha"]; if (CaptchaHelper.VerifyAndExpireSolution(HttpContext, myCaptcha, model.Captcha)) { // In a real app, actually register the user now if (ModelState.IsValid) { if (_TaiKhoanRepository.IsExistUserName(model.TenTaiKhoan)) { ModelState.AddModelError("", "Tài khoản đã tồn tại"); return View(model); } var tk = new TaiKhoan { TenTaiKhoan = model.TenTaiKhoan, MatKhau = MD5Helper.GetHash(model.MatKhau), Email = model.Email, HoTen = model.HoTen, DiaChi = model.DiaChi, CoQuan = model.Coquan, CMND = model.CMND, TinhTrang = 2, NhomNguoiDung = 1 }; var createStatus = _TaiKhoanRepository.CreateUser(tk); if (createStatus == MembershipCreateStatus.Success) //success { // Sign in return RedirectToAction("Index", "TrangChu"); } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } } } else { // Redisplay the view with an error message ModelState.AddModelError("", "Captcha nhập sai - Xin vui lòng nhập lại"); } return View(model); }
public ActionResult CapNhat(RegisterViewModel model, int id) { try { // Neu la chu tai khoan hoac admin thi hien thi edit tai khoan //TaiKhoan user = this.CurrentUser; var myCaptcha = Request.Form["myCaptcha"]; if (CaptchaHelper.VerifyAndExpireSolution(HttpContext, myCaptcha, model.Captcha)) { if (ModelState.IsValid) { TaiKhoan user = _TaiKhoanRepository.GetTaiKhoanByID(id); TaiKhoan editor = this.CurrentUser; if(user.MatKhau!= MD5Helper.GetHash(model.MatKhau)) { MessageHelper.CreateMessage(MessageType.Error,"Lỗi:", new List<string>{"Mật khẩu không đúng"},HttpContext.Response); return View(model); } if (editor.MaTaiKhoan == user.MaTaiKhoan || editor.NhomNguoiDung1.TenNhom.Equals("SuperAdmin")) { user.HoTen = model.HoTen; user.CoQuan = model.Coquan; user.CMND = model.CMND; user.DiaChi = model.DiaChi; user.Email = model.Email; user.MatKhau = MD5Helper.GetHash(model.NhapLaiMatKhau); _TaiKhoanRepository.Save(); return RedirectToAction("ChiTiet", "TaiKhoan", new { id = id }); } else { return View("NotAllowed"); } } } return View(model); // return } catch (Exception) { MessageHelper.CreateMessage(MessageType.Error, "", new List<string> { "error when update user" }, HttpContext.Response); } return RedirectToLogin(); }