public static void AuditExistingFullTimeEmployee(int existingEmpId, FullTimeEmployee newEmployee, String Username)
 {
     FullTimeEmployee ft = GetFullTimer(existingEmpId);
     CompareFields(ft.DateOfTermination.ToString(), newEmployee.DateOfTermination.ToString(), 12, 3, newEmployee.Employee.EmployeeId, Username);
     CompareFields(ft.Salary.ToString(), newEmployee.Salary.ToString(), 13, 2, newEmployee.Employee.EmployeeId, Username);
     CompareFields(ft.ReasonForLeavingId.ToString(), newEmployee.ReasonForLeavingId.ToString(), 7, 2, newEmployee.Employee.EmployeeId, Username);
 }
        public ActionResult FindEdit(FullTimeEmployee fulltimeemployee)
        {
            db = new EMSEntities12();
            String sin = fulltimeemployee.Employee.SIN_BN;
            EMSPSSUtilities.SINValid(ref sin);
            fulltimeemployee.Employee.SIN_BN = sin;
            if (fulltimeemployee.DateOfTermination == null)
            {
                fulltimeemployee.ReasonForLeavingId = null;
            }
            else if (fulltimeemployee.DateOfTermination != null && fulltimeemployee.ReasonForLeavingId == 0)
            {
                ModelState.AddModelError("ReasonForLeaving", "You must enter a reason for leaving.");
            }
            if (!EMSPSSUtilities.VerifySIN(fulltimeemployee.Employee.SIN_BN))
            {
                ModelState.AddModelError("SIN_BN", fulltimeemployee.Employee.SIN_BN + " is not a valid SIN.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(Convert.ToDateTime("1900-01-01"), fulltimeemployee.Employee.DateOfBirth))
            {
                ModelState.AddModelError("DOB", "Date of Birth must be past the year 1900.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(fulltimeemployee.Employee.DateOfBirth, DateTime.Now))
            {
                ModelState.AddModelError("DOB", "Date of Birth must be in the past.");
            }
            if (fulltimeemployee.DateOfTermination != null)
            {
                DateTime dot = (DateTime)fulltimeemployee.DateOfTermination;
                if (!EMSPSSUtilities.DateIsElapsed(fulltimeemployee.DateOfHire, dot))
                {
                    ModelState.AddModelError("DOT", "Date of Termination must be in the future from Date of Hire.");
                }
            }
            if (ModelState.IsValid)
            {
                EMSPSSUtilities.AuditExistingEmployee(fulltimeemployee.EmployeeRefId, fulltimeemployee.Employee, User.Identity.Name);
                EMSPSSUtilities.AuditExistingFullTimeEmployee(fulltimeemployee.EmployeeRefId, fulltimeemployee, User.Identity.Name);

                fulltimeemployee.Employee.Completed = EMSPSSUtilities.ValidateFullTimeEmployeeComplete(fulltimeemployee);

                fulltimeemployee.Company = db.Companies.Find(fulltimeemployee.EmployedWithId);

                db.Entry(fulltimeemployee.Employee).State = EntityState.Modified;
                db.SaveChanges();

                db.Entry(fulltimeemployee).State = EntityState.Modified;
                db.SaveChanges();

                //ModelState.AddModelError( validationError.PropertyName, validationError.ErrorMessage);

                return RedirectToAction("SearchIndex", "Home", new { FirstName = fulltimeemployee.Employee.FirstName, LastName = fulltimeemployee.Employee.LastName, SINBN = fulltimeemployee.Employee.SIN_BN });
            }

            return View(fulltimeemployee);
        }
        public static Boolean ValidateFullTimeEmployeeComplete(FullTimeEmployee ft)
        {
            Boolean complete = ValidateEmployeeComplete(ft.Employee);

            if (ft.DateOfHire == null)
            {
                complete = false;
            }
            else if (ft.Salary <= 0 || ft.Salary == null)
            {
                complete = false;
            }
            return complete;
        }
 //get a full time employee based on id
 public static FullTimeEmployee GetFullTimer(int id)
 {
     db = new EMSEntities12();
     FullTimeEmployee fulltimer = new FullTimeEmployee();
     List<FullTimeEmployee> ftl = db.FullTimeEmployees.ToList();
     foreach (FullTimeEmployee ft in ftl)
     {
         if (ft.EmployeeRefId == id)
         {
             fulltimer = ft;
             break;
         }
     }
     return fulltimer;
 }
        public ActionResult Fulltime(FullTimeEmployee FTemployee, string CompList, string name, string last, string day, string month, string year, string sin)
        {
            db = new EMSEntities12();
            EmployeeType ETemployee = new EmployeeType();
            Employee employee = new Employee();
            ViewBag.Employees = GetOptions();

            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;

            FTemployee.EmployeeRefId = employee.EmployeeId;

            foreach (Company mycmp in db.Companies)
            {
                if (mycmp.CompanyName == CompList)
                {
                    FTemployee.EmployedWithId = mycmp.CompanyId;
                }
            }
            ETemployee.CompanyId = FTemployee.EmployedWithId;

            ETemployee.EmployeeType1 = "Full Time";
            ETemployee.DateofHire = FTemployee.DateOfHire;

            if (CompList == "")
            {
                ModelState.AddModelError("comp", "This field is Required.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(employee.DateOfBirth, FTemployee.DateOfHire, 18))
            {
                ModelState.AddModelError("DOH", "A full time employee must be at least 18 years old.");
            }
            if (ModelState.IsValid)
            {

                db.Employees.Add(employee);
                db.SaveChanges();
                EMSPSSUtilities.AuditNewBaseEmployee(employee, User.Identity.Name);
                FTemployee.EmployeeRefId = employee.EmployeeId;
                ETemployee.EmployeeId = FTemployee.EmployeeRefId;
                EMSPSSUtilities.CompareFields("", FTemployee.DateOfHire.ToString(), 11, 1, FTemployee.EmployeeRefId, User.Identity.Name);

                db.FullTimeEmployees.Add(FTemployee);
                db.EmployeeTypes.Add(ETemployee);
                db.SaveChanges();
                return RedirectToAction("SearchIndex", "Home", new { FirstName = FTemployee.Employee.FirstName, LastName = FTemployee.Employee.LastName, SINBN = FTemployee.Employee.SIN_BN });
            }

            ViewBag.CompName = EMSPSSUtilities.GetCompList();
            return View(FTemployee);
        }
 public ActionResult Fulltime(Employee employee, string name, string last, string day, string month, string year, string sin)
 {
     FullTimeEmployee FTemployee = new FullTimeEmployee();
     ViewBag.Employees = GetOptions();
     ViewBag.CompName = EMSPSSUtilities.GetCompList();
     return View(FTemployee);
 }