public static void AuditExistingPartTimeEmployee(int existingEmpId, PartTimeEmployee newEmployee, String Username) { PartTimeEmployee pt = GetPartTimer(existingEmpId); CompareFields(pt.DateOfTermination.ToString(), newEmployee.DateOfTermination.ToString(), 12, 3, newEmployee.Employee.EmployeeId, Username); CompareFields(pt.HourlyRate.ToString(), newEmployee.HourlyRate.ToString(), 15, 2, newEmployee.Employee.EmployeeId, Username); CompareFields(pt.ReasonForLeaving2Id.ToString(), newEmployee.ReasonForLeaving2Id.ToString(), 7, 2, newEmployee.Employee.EmployeeId, Username); }
public ActionResult FindEdit(PartTimeEmployee parttimeemployee) { db = new EMSEntities12(); String sin = parttimeemployee.Employee.SIN_BN; EMSPSSUtilities.SINValid(ref sin); parttimeemployee.Employee.SIN_BN = sin; if (parttimeemployee.DateOfTermination == null) { parttimeemployee.ReasonForLeaving2Id = null; } else if (parttimeemployee.DateOfTermination != null && parttimeemployee.ReasonForLeaving2Id == 0) { ModelState.AddModelError("ReasonForLeaving", "You must enter a reason for leaving."); } if (!EMSPSSUtilities.VerifySIN(parttimeemployee.Employee.SIN_BN)) { ModelState.AddModelError("SIN_BN", parttimeemployee.Employee.SIN_BN + " is not a valid SIN."); } if (!EMSPSSUtilities.DateIsElapsed(Convert.ToDateTime("1900-01-01"), parttimeemployee.Employee.DateOfBirth)) { ModelState.AddModelError("DOB", "Date of Birth must be past the year 1900."); } if (!EMSPSSUtilities.DateIsElapsed(parttimeemployee.Employee.DateOfBirth, DateTime.Now)) { ModelState.AddModelError("DOB", "Date of Birth must be in the past."); } if (parttimeemployee.DateOfTermination != null) { DateTime dot = (DateTime)parttimeemployee.DateOfTermination; if (!EMSPSSUtilities.DateIsElapsed(parttimeemployee.DateOfHire, dot)) { ModelState.AddModelError("DOT", "Date of Termination must be in the future from Date of Hire."); } } if (ModelState.IsValid) { EMSPSSUtilities.AuditExistingEmployee(parttimeemployee.EmployeeRef2Id, parttimeemployee.Employee, User.Identity.Name); EMSPSSUtilities.AuditExistingPartTimeEmployee(parttimeemployee.EmployeeRef2Id, parttimeemployee, User.Identity.Name); parttimeemployee.Company = db.Companies.Find(parttimeemployee.EmployedWith2Id); parttimeemployee.Employee.Completed = EMSPSSUtilities.ValidatePartTimeEmployeeComplete(parttimeemployee); db.Entry(parttimeemployee.Employee).State = EntityState.Modified; db.SaveChanges(); db.Entry(parttimeemployee).State = EntityState.Modified; db.SaveChanges(); //ModelState.AddModelError( validationError.PropertyName, validationError.ErrorMessage); return RedirectToAction("SearchIndex", "Home", new { FirstName = parttimeemployee.Employee.FirstName, LastName = parttimeemployee.Employee.LastName, SINBN = parttimeemployee.Employee.SIN_BN }); } return View(parttimeemployee); }
public static Boolean ValidatePartTimeEmployeeComplete(PartTimeEmployee pt) { Boolean complete = ValidateEmployeeComplete(pt.Employee); if (pt.DateOfHire == null) { complete = false; } else if (pt.HourlyRate <= 0 || pt.HourlyRate == null) { complete = false; } return complete; }
//get a part time employee based on id public static PartTimeEmployee GetPartTimer(int id) { db = new EMSEntities12(); PartTimeEmployee parttimer = new PartTimeEmployee(); List<PartTimeEmployee> ptl = db.PartTimeEmployees.ToList(); foreach (PartTimeEmployee pt in ptl) { if (pt.EmployeeRef2Id == id) { parttimer = pt; break; } } return parttimer; }
public ActionResult PartTime(PartTimeEmployee PTemployee, string CompList, string name, string last, string day, string month, string year, string sin) { db = new EMSEntities12(); EmployeeType ETemployee = new EmployeeType(); ViewBag.Employees = GetOptions(); ViewBag.CompName = EMSPSSUtilities.GetCompList(); Employee employee = new Employee(); employee.FirstName = name; employee.LastName = last; int Year = 0, Month = 0, Day = 0; Int32.TryParse(year, out Year); Int32.TryParse(day, out Day); Int32.TryParse(month, out Month); employee.DateOfBirth = new DateTime(Year, Month, Day); employee.SIN_BN = sin; employee.Completed = false; foreach (Company mycmp in db.Companies) { if (mycmp.CompanyName == CompList) { PTemployee.EmployedWith2Id = mycmp.CompanyId; } } ETemployee.CompanyId = PTemployee.EmployedWith2Id; ETemployee.EmployeeType1 = "Part Time"; ETemployee.DateofHire = PTemployee.DateOfHire; PTemployee.Employee = employee; if (CompList == "") { ModelState.AddModelError("comp", "This field is Required."); } if (!EMSPSSUtilities.DateIsElapsed(employee.DateOfBirth, PTemployee.DateOfHire, 16)) { ModelState.AddModelError("DOH", "A part time employee must be at least 16 years old."); } if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); EMSPSSUtilities.AuditNewBaseEmployee(employee, User.Identity.Name); PTemployee.EmployeeRef2Id = employee.EmployeeId; ETemployee.EmployeeId = PTemployee.EmployeeRef2Id; EMSPSSUtilities.CompareFields("", PTemployee.DateOfHire.ToString(), 11, 1, PTemployee.EmployeeRef2Id, User.Identity.Name); db.PartTimeEmployees.Add(PTemployee); db.EmployeeTypes.Add(ETemployee); db.SaveChanges(); return RedirectToAction("SearchIndex", "Home", new { FirstName = PTemployee.Employee.FirstName, LastName = PTemployee.Employee.LastName, SINBN = PTemployee.Employee.SIN_BN }); } return View(PTemployee); }
public ActionResult PartTime(string name, string last, string day, string month, string year, string sin) { PartTimeEmployee employee = new PartTimeEmployee(); ViewBag.Employees = GetOptions(); ViewBag.CompName = EMSPSSUtilities.GetCompList(); return View(employee); }