public ActionResult AddAdmin(UserRegister userInfo) { if (Session["AdminId"] == null) { return(RedirectToAction("Login", "Home")); } else { if (db.UserInfoes.Any(e => e.Email == userInfo.Email)) { ModelState.AddModelError("Email", "Email is already in use"); } if (ModelState.IsValid) { UserInfo ui = new UserInfo(); ui.Type = userInfo.Type; ui.Name = userInfo.Name; ui.Passward = CryptPassword.Hash(userInfo.Passward); ui.Email = userInfo.Email; ui.Gender = userInfo.Gender; ui.DepId = null; ui.Active = null; ui.Accepted = null; ui.AbsenceHours = null; db.UserInfoes.Add(ui); db.SaveChangesAsync(); return(RedirectToAction("Users", "Admin")); } return(View(userInfo)); } }
public ActionResult ChangePassword(ChangePassword changepass) { if (Session["AdminId"] == null) { return(RedirectToAction("Login", "Home")); } else { if (ModelState.IsValid) { int id = int.Parse(Session["AdminId"].ToString()); var myAcc = db.UserInfoes.Single(a => a.Id == id); if (myAcc.Passward == CryptPassword.Hash(changepass.OldPassword)) { myAcc.Passward = CryptPassword.Hash(changepass.NewPassword); db.SaveChanges(); return(RedirectToAction("Index", "Admin")); } else { ViewBag.msg = "Old Passoed is InCorrect"; } } else { return(View()); } return(View()); } }
public ActionResult Register(UserRegister userInfo) { // check if Email is already in use or no if (db.UserInfoes.Any(e => e.Email == userInfo.Email)) { // if Email is already in use => add model error ModelState.AddModelError("Email", "Email is already in use"); } if (ModelState.IsValid) { UserInfo ui = new UserInfo(); ui.Type = userInfo.Type; ui.Name = userInfo.Name; ui.Passward = CryptPassword.Hash(userInfo.Passward); ui.Email = userInfo.Email; ui.Gender = userInfo.Gender; ui.DepId = userInfo.DepId; ui.Active = false; ui.Accepted = false; ui.AbsenceHours = 0; db.UserInfoes.Add(ui); db.SaveChangesAsync(); return(RedirectToAction("Login")); } ViewBag.DepId = new SelectList(db.Departments, "DepId", "DepName"); return(View(userInfo)); }
public ActionResult Login(UserLogin user) { // validation if (ModelState.IsValid) { string pass = CryptPassword.Hash(user.Passward); var UserCheck = db.UserInfoes.Where(x => x.Type == user.Type && x.Email == user.Email && x.Passward == pass).FirstOrDefault(); if (UserCheck != null) { // if user type => admin => redirect it to 'AdminController' if (user.Type == "Admin") { Session["AdminId"] = UserCheck.Id; Session["AdminName"] = UserCheck.Name; return(RedirectToAction("Index", "Admin")); } // if user type => head =>if he accepted redirect it to 'HeadController' else if (user.Type == "Head") { if (UserCheck.Accepted == true) { Session["HeadId"] = UserCheck.Id; Session["HeadName"] = UserCheck.Name; return(RedirectToAction("Index", "Head")); } else { ViewBag.msgApproved = "Not Approved"; } } // if user type => head =>if he accepted redirect it to 'EmployeeController' else if (user.Type == "Employee") { if (UserCheck.Accepted == true) { Session["EmpId"] = UserCheck.Id; Session["EmpName"] = UserCheck.Name; return(RedirectToAction("Index", "Employee")); } else { ViewBag.msg = "Not Approved"; } } } else { ViewBag.msg = "Email or Password is Incorrect"; } return(View()); } else { return(View()); } }
public ActionResult EditMe(UserInfo user) { if (Session["AdminId"] == null) { return(RedirectToAction("Login", "Home")); } else { if (ModelState.IsValid) { int id = int.Parse(Session["AdminId"].ToString()); var myAcc = db.UserInfoes.Single(a => a.Id == id); string passwordCome = CryptPassword.Hash(user.Passward); if (myAcc.Passward == passwordCome) { if (myAcc.Email != user.Email) { if (db.UserInfoes.Any(e => e.Email == user.Email)) { ViewBag.msg = "This Email is already in use"; } else { myAcc.Name = user.Name; myAcc.Gender = user.Gender; myAcc.Email = user.Email; db.SaveChanges(); Session["AdminName"] = myAcc.Name; return(RedirectToAction("Index", "Admin")); } } else { myAcc.Name = user.Name; myAcc.Gender = user.Gender; db.SaveChanges(); return(RedirectToAction("Index", "Admin")); } } else { ViewBag.msg = "Password in Incorrect"; } } else { return(View()); } return(View()); } }