예제 #1
0
        public ActionResult Create(Company company)
        {
            db = new EMSEntities12();
            if (ModelState.IsValid)
            {
                List<Company> companyList = db.Companies.ToList();
                bool companyExists = false;

                for (int x = 0; x < companyList.Count; ++x)
                {
                    if (companyList[x].CompanyName == company.CompanyName)
                    {
                        companyExists = true;
                    }
                }
                if (!companyExists && company.CompanyName != null)
                {
                        company.EnrolledSince = DateTime.Now;
                        db.Companies.Add(company);
                        db.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            return View(company);
        }
        public ActionResult FindEdit(SeasonalEmployee seasonalemployee)
        {
            db = new EMSEntities12();
            if (seasonalemployee.ReasonForLeaving3Id == 0)
            {
                seasonalemployee.ReasonForLeaving3Id = null;
            }
            String sin = seasonalemployee.Employee.SIN_BN;
            EMSPSSUtilities.SINValid(ref sin);
            seasonalemployee.Employee.SIN_BN = sin;
            if (!EMSPSSUtilities.VerifySIN(seasonalemployee.Employee.SIN_BN))
            {
                ModelState.AddModelError("SIN_BN", seasonalemployee.Employee.SIN_BN + " is not a valid SIN.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(Convert.ToDateTime("1900-01-01"), seasonalemployee.Employee.DateOfBirth))
            {
                ModelState.AddModelError("DOB", "Date of Birth must be past the year 1900.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(seasonalemployee.Employee.DateOfBirth, DateTime.Now))
            {
                ModelState.AddModelError("DOB", "Date of Birth must be in the past.");
            }

            if (ModelState.IsValid)
            {
                EMSPSSUtilities.AuditExistingEmployee(seasonalemployee.EmployeeRef3Id, seasonalemployee.Employee, User.Identity.Name);
                EMSPSSUtilities.AuditExistingSeasonalEmployee(seasonalemployee.EmployeeRef3Id, seasonalemployee, User.Identity.Name);

                seasonalemployee.Company = db.Companies.Find(seasonalemployee.EmployedWith3Id);

                seasonalemployee.Employee.Completed = EMSPSSUtilities.ValidateSeasonalEmployeeComplete(seasonalemployee);

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

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

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

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

            return View(seasonalemployee);
        }
예제 #3
0
 public ActionResult Edit(Company company)
 {
     db = new EMSEntities12();
     if (ModelState.IsValid)
     {
         db.Entry(company).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(company);
 }
예제 #4
0
        public ActionResult Edit(int EmployeeId, DateTime? piecesDate)
        {
            db = new EMSEntities12();
            int CompanyId = EMSPSSUtilities.GetCompanyId(EmployeeId);
            if (piecesDate != null)
            {
                DateTime weekOf = piecesDate.Value;
                while (weekOf.DayOfWeek != DayOfWeek.Monday)
                {
                    weekOf = weekOf.AddDays(-1);
                }

                foreach (Piece tmp in db.Pieces)
                {
                    if ((tmp.EmployeeRef6Id == EmployeeId) && (tmp.EmployedWith6Id == CompanyId) && (tmp.WeekOf == weekOf))
                    {
                        return View(tmp);
                    }
                }
                // if it reaches here, the timecard was not found
                // create and add it before proceeding

                Piece newPiece = new Piece();
                newPiece.EmployedWith6Id = CompanyId;
                newPiece.EmployeeRef6Id = EmployeeId;
                newPiece.WeekOf = weekOf;
                newPiece.Mon = null;
                newPiece.Tue = null;
                newPiece.Wed = null;
                newPiece.Thu = null;
                newPiece.Fri = null;
                newPiece.Sat = null;
                newPiece.Sun = null;

                db.Pieces.Add(newPiece);
                db.SaveChanges();

                return View(newPiece);
            }
            return RedirectToAction("Index", "Pieces", new { EmployeeId = EmployeeId, CompanyId = CompanyId });
        }
예제 #5
0
 public ActionResult Edit(Piece piece)
 {
     db = new EMSEntities12();
     if (ModelState.IsValid)
     {
         db.Entry(piece).State = EntityState.Modified;
         db.SaveChanges();
         foreach (Employee emp in db.Employees)
         {
             if (emp.EmployeeId == piece.EmployeeRef6Id)
             {
                 ViewBag.Name = emp.FirstName + " " + emp.LastName;
                 break;
             }
         }
         foreach (Company cmp in db.Companies)
         {
             if (cmp.CompanyId == piece.EmployedWith6Id)
             {
                 ViewBag.Company = cmp.CompanyName;
                 break;
             }
         }
         ViewBag.EmployeeId = piece.EmployeeRef6Id;
         ViewBag.CompanyId = piece.EmployedWith6Id;
         return RedirectToAction("Index", "Pieces", new { EmployeeId = piece.EmployeeRef6Id, CompanyId = piece.EmployedWith6Id });
     }
     return View(piece);
 }
        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);
        }
예제 #7
0
        public ActionResult Edit(int EmployeeId, DateTime? timeCardDate)
        {
            db = new EMSEntities12();
            int CompanyId = EMSPSSUtilities.GetCompanyId(EmployeeId);
            if (timeCardDate != null)
            {

                DateTime weekOf = (DateTime)timeCardDate.Value;
                while (weekOf.DayOfWeek != DayOfWeek.Monday)
                {
                    weekOf = weekOf.AddDays(-1);
                }

                TimeCard tc = new TimeCard();
                List<TimeCard> allTCs = db.TimeCards.ToList();

                foreach (TimeCard tmp in allTCs)
                {
                    if ((tmp.EmployeeRef5Id == EmployeeId) && (tmp.EmployedWith5Id == CompanyId) && (tmp.WeekOf == weekOf))
                    {
                        return View(tmp);
                    }
                }
                // if it reaches here, the timecard was not found
                // create and add it before proceeding

                tc.EmployedWith5Id = CompanyId;
                tc.EmployeeRef5Id = EmployeeId;
                tc.Employee = db.Employees.Find(EmployeeId);
                tc.Company = db.Companies.Find(CompanyId);
                tc.WeekOf = weekOf;
                tc.Mon = null;
                tc.Tue = null;
                tc.Wed = null;
                tc.Thu = null;
                tc.Fri = null;
                tc.Sat = null;
                tc.Sun = null;

                db.TimeCards.Add(tc);
                db.SaveChanges();

                return View(tc);
            }
            return RedirectToAction("Index", "TimeCard", new { EmployeeId = EmployeeId, CompanyId = CompanyId });
        }
예제 #8
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                //Roles.CreateRole("Admin");
                //Roles.AddUserToRole("Kyle", "Admin");
                EMSEntities12 db = new EMSEntities12();
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipCreateStatus.Success;
                User u = new User();
                u.FirstName = model.FirstName;
                u.LastName = model.LastName;
                u.UserName = model.UserName;
                List<User> l = db.Users.ToList();
                foreach (User user in l)
                {
                    if (user.UserName.ToLower() == model.UserName.ToLower())
                    {
                        createStatus = MembershipCreateStatus.DuplicateUserName;
                    }
                }
                if (createStatus == MembershipCreateStatus.Success)
                {

                    db.Users.Add(u);
                    db.SaveChanges();
                    Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
                    if (model.IsAdmin == "True")
                    {
                        Roles.AddUserToRole(model.UserName, "Admin");
                    }
                }
                if (createStatus == MembershipCreateStatus.Success)
                {

                    ViewBag.SuccessMessage = "User \"" + model.UserName + "\" was successfully created.";
                    //FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return View();
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #9
0
 // ----Params----
 // String OldVal == old value
 // String NewVal == new value
 // int FieldnameId == Id of the field name in the field name table
 // int auditTypeId == Id of the audit action in the Audit action table
 // int employeeId == Id of the employee being looked at
 // String Username == username of the person who did the action
 public static void CompareFields(String OldVal, String NewVal, int FieldnameId, int auditTypeId, int employeeId, String Username)
 {
     db = new EMSEntities12();
     Audit audit = new Audit();
     if (OldVal != NewVal)
     {
         audit.UserName = Username;
         audit.DateTime = DateTime.Now;
         audit.AuditTypeId = auditTypeId;
         audit.FieldId = FieldnameId;
         audit.OldValue = OldVal;
         audit.NewValue = NewVal;
         audit.EmployeeId = employeeId;
         db.Audits.Add(audit);
         db.SaveChanges();
     }
 }
예제 #10
0
        public ActionResult ContractCreation(ContractEmployee ce, string CompList)
        {
            db = new EMSEntities12();
            if (CompList == "")
            {
                ModelState.AddModelError("comp", "This field is Required.");
            }
            ViewBag.CompName = EMSPSSUtilities.GetCompList();
            Employee e = ce.Employee;
            //e.EmployeeId = null;
            e.Completed = true;
            String sin = ce.Employee.SIN_BN;
            EMSPSSUtilities.SINValid(ref sin);
            ce.Employee.SIN_BN = sin;
            if (!EMSPSSUtilities.VerifySIN(ce.Employee.SIN_BN))
            {
                ModelState.AddModelError("SIN_BN", ce.Employee.SIN_BN + " is not a valid BN.");
            }
            if (!EMSPSSUtilities.VerifyBusinessNum(ce.Employee.SIN_BN, ce.Employee.DateOfBirth.ToString("yyyy-MM-dd")))
            {
                ModelState.AddModelError("SIN_BN", "The first two digits of a BN must match the last two digits of their date of incorporation.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(ce.Employee.DateOfBirth, ce.ContractStartDate))
            {
                ModelState.AddModelError("CSD", "Contract Start date must be in the future from date of incorporation.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(ce.ContractStartDate, ce.ContractStopDate))
            {
                ModelState.AddModelError("CSD2", "Contract Stop date must be in the future from Contract Start date.");
            }
            if (ModelState.IsValid)
            {
                db.Employees.Add(e);
                db.SaveChanges();

                foreach (Company mycmp in db.Companies)
                {
                    if (mycmp.CompanyName == CompList)
                    {
                        ce.EmployedWith4Id = mycmp.CompanyId;
                    }
                }
                ce.EmployeeRef4Id = e.EmployeeId;
                EmployeeType et = new EmployeeType();
                et.EmployeeId = e.EmployeeId;
                et.CompanyId = ce.EmployedWith4Id;
                et.DateofHire = ce.ContractStartDate;
                et.EmployeeType1 = "Contract";
                if (ce.ReasonForLeaving4Id == 0)
                {
                    ce.ReasonForLeaving4Id = null;
                }
                if (ModelState.IsValid)
                {
                    EMSPSSUtilities.AuditNewBaseEmployee(ce.Employee, User.Identity.Name);
                    EMSPSSUtilities.AuditNewContractEmployee(ce, User.Identity.Name);
                    db.ContractEmployees.Add(ce);
                    db.EmployeeTypes.Add(et);
                    db.SaveChanges();
                    return RedirectToAction("SearchIndex", "Home", new { FirstName = ce.Employee.FirstName, LastName = ce.Employee.LastName, SINBN = ce.Employee.SIN_BN });
                }

                return View(ce);
            }

            return View(ce);
        }
예제 #11
0
        public ActionResult Seasonal(SeasonalEmployee Semployee, string CompList, string SeasonLst, string name, string last, string day, string month, string year, string sin)
        {
            db = new EMSEntities12();
            ViewBag.SeasonName = EMSPSSUtilities.GetSeasonList();
            ViewBag.CompName = EMSPSSUtilities.GetCompList();
            EmployeeType ETemployee = new EmployeeType();
            ViewBag.Employees = GetOptions();

            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)
                {
                    Semployee.EmployedWith3Id = mycmp.CompanyId;
                }
            }

            foreach (Season myseas in db.Seasons)
            {
                if (myseas.Season1 == SeasonLst)
                {
                    Semployee.SeasonId = myseas.SeasonId;
                }
            }

            ETemployee.CompanyId = Semployee.EmployedWith3Id;
            ETemployee.EmployeeType1 = "Seasonal";
            ETemployee.DateofHire = Semployee.SeasonYear;
            if (CompList == "")
            {
                ModelState.AddModelError("comp", "This field is Required.");
            }
            if (SeasonLst == "")
            {
                ModelState.AddModelError("season", "This field is Required.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(employee.DateOfBirth, Semployee.SeasonYear, 18))
            {
                ModelState.AddModelError("DOH", "A seasonal employee must be at least 18 years old.");
            }
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                EMSPSSUtilities.AuditNewBaseEmployee(employee, User.Identity.Name);
                Semployee.EmployeeRef3Id = employee.EmployeeId;
                ETemployee.EmployeeId = Semployee.EmployeeRef3Id;
                EMSPSSUtilities.CompareFields("", Semployee.SeasonId.ToString(), 17, 1, Semployee.EmployeeRef3Id, User.Identity.Name);

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

            return View(Semployee);
        }
예제 #12
0
        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 FindEdit(ContractEmployee contractemployee)
        {
            db = new EMSEntities12();
            String sin = contractemployee.Employee.SIN_BN;
            EMSPSSUtilities.SINValid(ref sin);
            contractemployee.Employee.Completed = true;
            contractemployee.Employee.SIN_BN = sin;
            if (contractemployee.ReasonForLeaving4Id == 0)
            {
                contractemployee.ReasonForLeaving4Id = null;
            }
            if (!EMSPSSUtilities.VerifySIN(contractemployee.Employee.SIN_BN) || !EMSPSSUtilities.VerifyBusinessNum(contractemployee.Employee.SIN_BN, contractemployee.Employee.DateOfBirth.ToString("yyyy-MM-dd")))
            {
                ModelState.AddModelError("SIN_BN", contractemployee.Employee.SIN_BN + " is not a valid BN.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(Convert.ToDateTime("1600-01-01"), contractemployee.Employee.DateOfBirth))
            {
                ModelState.AddModelError("DOB", "Date of Incorporation must be past the year 1600.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(contractemployee.Employee.DateOfBirth, DateTime.Now))
            {
                ModelState.AddModelError("DOB", "Date of Incorporation must be in the past.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(contractemployee.Employee.DateOfBirth, contractemployee.ContractStartDate))
            {
                ModelState.AddModelError("CSD", "Contract Start date must be in the future from date of incorporation.");
            }
            if (!EMSPSSUtilities.DateIsElapsed(contractemployee.ContractStartDate, contractemployee.ContractStopDate))
            {
                ModelState.AddModelError("CSD2", "Contract Stop date must be in the future from Contract Start date.");
            }
            if (ModelState.IsValid)
            {
                EMSPSSUtilities.AuditExistingEmployee(contractemployee.EmployeeRef4Id, contractemployee.Employee, User.Identity.Name);
                EMSPSSUtilities.AuditExistingContractEmployee(contractemployee.EmployeeRef4Id, contractemployee, User.Identity.Name);

                contractemployee.Company = db.Companies.Find(contractemployee.EmployedWith4Id);

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

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

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

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