public ActionResult ChangePassword(CompteConfigViewModel CompteCVM) { using (WakilRecouvContext WakilContext = new WakilRecouvContext()) { using (UnitOfWork UOW = new UnitOfWork(WakilContext)) { RoleService RoleService = new RoleService(UOW); EmployeService EmpService = new EmployeService(UOW); Employe e = EmpService.GetEmployeByUername(Session["username"].ToString()); if (e.Password == CompteCVM.Password) { e.Password = CompteCVM.NewPassword; e.ConfirmPassword = CompteCVM.NewPassword; EmpService.Update(e); EmpService.Commit(); } else { ModelState.AddModelError("Password", "Votre mot de passe actuel est incorrect"); } return(View()); } } }
public ActionResult InscriptionCompte(Employe emp) { using (WakilRecouvContext WakilContext = new WakilRecouvContext()) { using (UnitOfWork UOW = new UnitOfWork(WakilContext)) { RoleService RoleService = new RoleService(UOW); EmployeService EmpService = new EmployeService(UOW); var Roles = RoleService.GetAll(); ViewBag.RoleList = new SelectList(Roles, "RoleId", "role"); if (EmpService.GetEmployeByUername(emp.Username) != null) { ModelState.AddModelError("Username", "Nom d'utilisateur existe deja !"); } else { EmpService.Add(emp); EmpService.Commit(); return(RedirectToAction("Login")); } //Response.Write("<script>alert('" + emp.RoleId + "')</script>"); return(View()); } } }
public ActionResult Login(Compte compte) { using (WakilRecouvContext WakilContext = new WakilRecouvContext()) { using (UnitOfWork UOW = new UnitOfWork(WakilContext)) { EmployeService EmpService = new EmployeService(UOW); Employe emp = EmpService.GetEmployeByUername(compte.Username); if (emp == null) { ModelState.AddModelError("Username", "Nom d'utilisateur inexistant"); } else if (emp != null) { if (emp.Password == compte.Password) { if (emp.IsVerified == false) { ModelState.AddModelError("Connect", "Votre compte n'est pas encore validé par un administrateur"); } else if (emp.IsVerified == true) { Session["username"] = emp.Username; Session["role"] = emp.Role.role; return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("Password", "Mot de passe incorrect"); } } return(View()); } } }