public ActionResult ResetPassword(Employee thisEmp, int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } string message; //Don't check include in validation check ModelState.Remove("UserEmail"); ModelState.Remove("EmpFName"); ModelState.Remove("EmpLName"); ModelState.Remove("EmpPhone"); ModelState.Remove("EmpType"); if (ModelState.IsValid) { using (Entities dc = new Entities()) { GrizzTime.Models.employee emp = dc.employees.FirstOrDefault(p => p.UserID == id); if (thisEmp == null) { return(HttpNotFound()); } emp.UserPW = Hash(thisEmp.UserPW); emp.UserStatus = "Activated"; dc.Entry(emp).State = System.Data.Entity.EntityState.Modified; try { dc.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception exception = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message1 = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); //create a new exception inserting the current one //as the InnerException exception = new InvalidOperationException(message1, exception); } } throw exception; } } TempData["message"] = "Success! Please log in."; return(RedirectToAction("Login", "Employee")); } else { message = "Couldn't complete request."; } //SendVerificationEMail(thisEmp.UserEmail); TempData["message"] = message; return(View(thisEmp)); }
public ActionResult EditPayRate(int?id, Employee thisEmp) { if (Request.Cookies["UserID"].Value == null) { //Redirect to login if it can't find user id TempData["message"] = "Please log in."; System.Diagnostics.Debug.WriteLine("User not logged in. Redirecting to login page.\n"); return(RedirectToAction("LandingPage", "Home")); } ViewBag.UserID = Request.Cookies["UserID"].Value; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } bool Status = false; string message = ""; //Don't check include in validation check ModelState.Remove("UserEmail"); ModelState.Remove("EmpFName"); ModelState.Remove("EmpLName"); ModelState.Remove("EmpPhone"); ModelState.Remove("UserPW"); ModelState.Remove("EmpType"); ModelState.Remove("ConfirmPassword"); if (ModelState.IsValid) { using (Entities dc = new Entities()) { GrizzTime.Models.employee emp = dc.employees.FirstOrDefault(p => p.UserID == id); if (thisEmp == null) { return(HttpNotFound()); } emp.EmpPayRate = thisEmp.EmpPayRate; dc.Entry(emp).State = System.Data.Entity.EntityState.Modified; try { dc.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception exception = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message1 = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); //create a new exception inserting the current one //as the InnerException exception = new InvalidOperationException(message1, exception); } } throw exception; } } message = "Pay rate updated successfully."; Status = true; TempData["message"] = message; ViewBag.Status = Status; return(RedirectToAction("MyEmployees", "Business")); } else { message = "Invalid Request"; } TempData["message"] = message; ViewBag.Status = Status; return(View(thisEmp)); }
public ActionResult Create([Bind(Exclude = "IsEmailVerified,ActivationCode")] Employee thisEmp) { bool Status = false; string message; if (Request.Cookies["UserID"].Value == null) { //Redirect to login if it can't find business id TempData["message"] = "Please log in."; System.Diagnostics.Debug.WriteLine("User not logged in. Redirecting to login page.\n"); return(RedirectToAction("LandingPage", "Home")); } int id = Int32.Parse(Request.Cookies["UserID"].Value); ModelState.Remove("UserPW"); ModelState.Remove("ConfirmPassword"); //ensure that the model exists if (ModelState.IsValid) { //Email already exists var isExist = IsEmailExist(thisEmp.UserEmail); if (isExist) { ModelState.AddModelError("EmailExist", "An employee with this email address already exists."); return(View(thisEmp)); } using (Entities dc = new Entities()) { GrizzTime.Models.employee emp = new GrizzTime.Models.employee(); emp.UserEmail = thisEmp.UserEmail; emp.EmpFName = thisEmp.EmpFName; emp.EmpLName = thisEmp.EmpLName; emp.EmpPhone = thisEmp.EmpPhone; emp.EmpType = thisEmp.EmpType; emp.SupervisorID = thisEmp.SupervisorID; emp.BusCode = id; emp.UserStatus = "Registered"; dc.employees.Add(emp); dc.SaveChanges(); //Get id of employee just created. var justCreated = dc.employees.Where(a => a.UserEmail == thisEmp.UserEmail).FirstOrDefault(); if (justCreated == null) { TempData["message"] = "Something went wrong with SQL query."; return(View()); } SendRegistrationEMail(thisEmp.UserEmail, justCreated.UserID); } message = "A link to finish registration was sent to the employee."; Status = true; } else { message = "Invalid Request"; } TempData["message"] = message; ViewBag.UserID = Request.Cookies["UserID"].Value; ViewBag.Status = Status; return(RedirectToAction("Create", "Employee")); }