Beispiel #1
0
        public void TestAddEmployee()
        {
            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an manager.
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            manager.IsActive     = true;
            manager.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            manager.SetRoleList(employeeRoleList);
            manager.Save();
            Guid guid = manager.PKEmployeeID;

            Employee employee = EmployeeBLL.AddEmployee(Guid.NewGuid().ToString(), "Brandon", "None", "Shen", Sex.Male, 10, DateTime.Now, manager.Email, "5030", 0, "");

            Assert.IsTrue(null != employee && employee.FKReportManagerID.Equals(manager.PKEmployeeID));
            employee.Delete();
            manager.Delete();
            role.Delete();
        }
Beispiel #2
0
        public static Employee AddEmployee(string email, string firstName, string middleName, string lastName, Sex gender, float serviceYear, DateTime dateOfHire, string supervisorEmail, string costCenterCode, int employeeNum, string legalName)
        {
            Employee employee = null;

            if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName))
            {
                employee              = Employee.CreateEmployee(email, CryptographyStuff.AES_EncryptString(GlobalParams.DefaultPwd), gender, firstName, dateOfHire, lastName);
                employee.MiddleName   = middleName;
                employee.Gender       = gender;
                employee.ServiceYears = serviceYear;
                employee.IsActive     = true;
                employee.EmployeeNum  = employeeNum;
                employee.LegalName    = legalName;

                Role role = Role.GetRoleByName(RoleRank.Employee.ToString());
                List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();
                employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
                employee.SetRoleList(employeeRoleList);

                if (!string.IsNullOrEmpty(supervisorEmail))
                {
                    List <SearchCondition> conditions = new List <SearchCondition>();
                    conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Email, supervisorEmail, SearchComparator.Equal, SearchType.SearchString));
                    Employee manager = CommonDAL <Employee> .GetSingleObject(conditions);

                    employee.FKReportManagerID = manager.PKEmployeeID;
                }

                employee.CostCenter = costCenterCode;

                employee.Save();
            }

            return(employee);
        }
Beispiel #3
0
        public void TestLogin()
        {
            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid guid = employee.PKEmployeeID;

            Employee testEmployee1 = EmployeeBLL.Login(employee.Email, employee.Password);
            Employee testEmployee2 = EmployeeBLL.Login(employee.Email, employee.Password + "test");

            Assert.IsTrue(testEmployee1.PKEmployeeID.Equals(employee.PKEmployeeID) && testEmployee2 == null);

            employee.Delete();
            role.Delete();
        }
Beispiel #4
0
        public void TestDeleteEmployee()
        {
            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();

            // Delete the employee
            employee.Delete();

            // Get the employee who is deleted
            Guid guid = employee.PKEmployeeID;
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKEmployeeID", guid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            Employee testEmployee = CommonDAL <Employee> .GetSingleObject(conditions);

            Assert.IsNull(testEmployee);
            role.Delete();
        }
Beispiel #5
0
        public void TestDeleteEmployeeLeaveSummary()
        {
            // Insert an employee role
            Role employeeRole = Role.CreateRole(Guid.NewGuid().ToString());

            employeeRole.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Tian", DateTime.Now, "Liu");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, employeeRole.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.SetKnowledgeDate(DateTime.Now);
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert an employee leave summary
            EmployeeLeaveSummary employeeLeaveSummary = EmployeeLeaveSummary.CreateEmployeeLeaveSummary(employeeGuid, leaveTypeGuid, DateTime.Now.Year);

            employeeLeaveSummary.PKELSID   = Guid.NewGuid();
            employeeLeaveSummary.UsedHours = 10;
            employeeLeaveSummary.Save();
            Guid summaryGuid = employeeLeaveSummary.PKELSID;

            // Delete the employee leave summary
            employeeLeaveSummary.Delete();

            // Get the inserted employee leave summary
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKELSID", summaryGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            EmployeeLeaveSummary testSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions);

            Assert.IsNull(testSummary);

            // Delete inserted items
            leaveType.Delete();
            employee.Delete();
            employeeRole.Delete();
        }
Beispiel #6
0
        public void TestUpdateEmployeeRoleRL()
        {
            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();
            Guid roleGuid = role.PKRoleID;

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "TIAN", DateTime.Now, "LIU");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            EmployeeRoleRL        employeeRoleRL   = EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleGuid);
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(employeeRoleRL);
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid       = employee.PKEmployeeID;
            Guid employeeRoleRLGuid = employeeRoleRL.PKEmployeeRoleRLID;

            // Get the inserted employee role relation
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKEmployeeRoleRLID", employeeRoleRLGuid.ToString(),
                                                                 SearchComparator.Equal, SearchType.SearchString));
            EmployeeRoleRL testEemployeeRoleRL = CommonDAL <EmployeeRoleRL> .GetSingleObject(conditions);

            // Insert another role
            Role updatedRole = Role.CreateRole("UpdatedRole");

            updatedRole.Save();
            Guid updatedRoleGuid = updatedRole.PKRoleID;

            // Update the inserted emmployee role relation
            testEemployeeRoleRL.FKRoleID = updatedRoleGuid;
            testEemployeeRoleRL.Save();

            // Get the employee role relation updated just now
            EmployeeRoleRL updatedEmployeeRoleRL = CommonDAL <EmployeeRoleRL> .GetSingleObject(conditions);

            Assert.AreEqual(testEemployeeRoleRL.FKRoleID, updatedEmployeeRoleRL.FKRoleID);

            // Delete inseted items
            employeeRoleRL.Delete();
            employee.Delete();
            role.Delete();
            updatedRole.Delete();
        }
Beispiel #7
0
        private static void TestAddEmployee()
        {
            Role role = Role.GetRoleByName(RoleRank.Employee.ToString());

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(string.Format("GOGOGOGGO{0}", Guid.NewGuid().ToString().Substring(0, 4)), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
        }
Beispiel #8
0
        public void TestUpdateEmployeeTransact()
        {
            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive     = true;
            employee.Password     = "******";
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid guid = employee.PKEmployeeID;

            // Get the employee who is inserted just now.
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKEmployeeID", guid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            Employee testEmployee = CommonDAL <Employee> .GetSingleObject(conditions);

            // Update the employee.
            testEmployee.Email = "BrandonBrandon";
            try
            {
                testEmployee.Save();
            }
            catch
            {
                Console.WriteLine("Throw exception for transact unit test");
            }


            // Get the employee who is updated just now.
            Employee updatedEmployee = CommonDAL <Employee> .GetSingleObject(conditions);

            Assert.AreNotEqual(testEmployee.Email, updatedEmployee.Email);

            employee.Delete();
            role.Delete();
        }
Beispiel #9
0
        public void TestUpdateEmployee()
        {
            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid guidEmployee = employee.PKEmployeeID;

            // Insert an manager.
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Brandon", DateTime.Now, "Shen");

            manager.IsActive     = true;
            manager.ServiceYears = 10;
            employeeRoleList     = new List <EmployeeRoleRL>();
            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            manager.SetRoleList(employeeRoleList);
            manager.Save();
            Guid guidManager = manager.PKEmployeeID;

            EmployeeBLL.UpdateEmployee(employee.PKEmployeeID.ToString(), employee.Email, "nono", employee.MiddleName,
                                       employee.LastName, employee.Gender, employee.ServiceYears, employee.HiredDate,
                                       manager.Email, employee.Password, "999", employee.Mobile, true, true, true, "5030", 0, "");

            employee = EmployeeBLL.GetEmployeeByID(employee.PKEmployeeID.ToString());

            Assert.IsTrue(employee.IsPointedRole(role.Name) &&
                          employee.FKReportManagerID == manager.PKEmployeeID &&
                          employee.FirstName.Equals("nono") &&
                          employee.Phone.Equals("999"));

            employee.Delete();
            manager.Delete();
            role.Delete();
        }
Beispiel #10
0
        public void TestTimeDurationInfoTimeStamp()
        {
            // Insert an employee role
            Role employeeRole = Role.CreateRole(Guid.NewGuid().ToString());

            employeeRole.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Tian", DateTime.Now, "Liu");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, employeeRole.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.SetKnowledgeDate(DateTime.Now);
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime   = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            List <TimeDurationInfo> timeDurationList  = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);

            // Insert a leave info
            LeaveInfo leaveInfo = LeaveInfo.CreateLeaveInfo(employeeGuid, managerGuid, leaveTypeGuid, LeaveStatus.Accepted,
                                                            "For Test", "Test Description", timeDurationList);

            leaveInfo.Save();
            Guid leaveGuid = leaveInfo.PKLeaveInfoID;

            timeDurationInfo.FKLeaveInfoID = leaveGuid;
            timeDurationInfo.KnowledgeDate = DateTime.Now;
            timeDurationInfo.IsDeleted     = false;
            timeDurationInfo.Save();
            Guid tdGuid = timeDurationInfo.PKTDInfoID;

            // Get the inserted time duration info
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKTDInfoID", tdGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            TimeDurationInfo testTimeDuration1 = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions);

            TimeDurationInfo testTimeDuration2 = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions);

            // Update the inseted time duratioin info
            testTimeDuration1.EndTime = Convert.ToDateTime("02/10/2001");
            testTimeDuration1.Save();
            testTimeDuration2.EndTime = Convert.ToDateTime("02/11/2002");
            testTimeDuration2.Save();

            // Get the updated time duration info
            TimeDurationInfo updatedTimeDuration = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions);

            Assert.AreEqual(testTimeDuration1.EndTime, updatedTimeDuration.EndTime);
            Assert.AreNotEqual(testTimeDuration2.EndTime, updatedTimeDuration.EndTime);

            // Delete inserted items
            timeDurationInfo.Delete();
            leaveInfo.Delete();
            leaveType.Delete();
            employee.Delete();
            manager.Delete();
            employeeRole.Delete();
            managerRole.Delete();
        }
Beispiel #11
0
        public void TestApproveLeave()
        {
            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive          = true;
            employee.ServiceYears      = 10;
            employee.FKReportManagerID = managerGuid;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime  = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime    = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo   = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            DateTime                durationStartTime2 = Convert.ToDateTime("02/02/2011");
            DateTime                durationEndTime2   = Convert.ToDateTime("02/05/2011");
            TimeDurationInfo        timeDurationInfo2  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2);
            List <TimeDurationInfo> timeDurationList   = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);
            timeDurationList.Add(timeDurationInfo2);

            LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList);

            // Approve the applying leave.
            LeaveBLL.ApproveLeave(managerGuid.ToString(), leave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted);

            // Get the employee's leave list
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("FKSubmitEmployeeID", employeeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            List <LeaveInfo> leaveList = CommonDAL <LeaveInfo> .GetObjects(conditions);

            Assert.IsTrue(leaveList[0].PKLeaveInfoID == leave.PKLeaveInfoID && leaveList[0].Status == LeaveStatus.Accepted);

            leave.Delete();
            leaveType.Delete();
            employee.Delete();
            role.Delete();
            manager.Delete();
            managerRole.Delete();
        }
Beispiel #12
0
        public void TestGetMyTeamLeaves()
        {
            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive          = true;
            employee.ServiceYears      = 10;
            employee.FKReportManagerID = managerGuid;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime  = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime    = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo   = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            DateTime                durationStartTime2 = Convert.ToDateTime("02/02/2011");
            DateTime                durationEndTime2   = Convert.ToDateTime("02/05/2011");
            TimeDurationInfo        timeDurationInfo2  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2);
            List <TimeDurationInfo> timeDurationList   = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);
            timeDurationList.Add(timeDurationInfo2);

            LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList);

            // Get the employee's leave list
            List <LeaveInfo> leaveList = LeaveBLL.GetMyTeamLeaves(managerGuid.ToString(), true);

            // Compare these two list
            bool result = leave.PKLeaveInfoID == leaveList[0].PKLeaveInfoID;

            if (result)
            {
                //foreach (LeaveInfo leave in leave)
                //{
                //    bool existAndEqual = false;
                //    foreach (LeaveInfo leaveItem in leaveList)
                //    {
                //        if (leave.FirstStartTime == leaveItem.FirstStartTime && leave.LastEndTime == leaveItem.LastEndTime)
                //        {
                //            existAndEqual = true;
                //            break;
                //        }
                //    }

                //    result = existAndEqual;
                //    if (!result) break;
                //}
            }

            Assert.IsTrue(result);

            //foreach (LeaveInfo leave in leave)
            //{
            leave.Delete();
            //}
            leaveType.Delete();
            employee.Delete();
            role.Delete();
            manager.Delete();
            managerRole.Delete();
        }
Beispiel #13
0
        public void TestUpdateLeaveInfoTransact()
        {
            // Insert an employee role
            Role employeeRole = Role.CreateRole(Guid.NewGuid().ToString());

            employeeRole.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Tian", DateTime.Now, "Liu");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, employeeRole.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.SetKnowledgeDate(DateTime.Now);
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime   = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            List <TimeDurationInfo> timeDurationList  = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);

            // Insert a leave info
            LeaveInfo leaveInfo = LeaveInfo.CreateLeaveInfo(employeeGuid, managerGuid, leaveTypeGuid, LeaveStatus.Accepted,
                                                            "For Test", "Test Description", timeDurationList);

            leaveInfo.Save();
            Guid leaveGuid = leaveInfo.PKLeaveInfoID;

            // Get the leave info inserted just now
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKLeaveInfoID", leaveGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            LeaveInfo testLeaveInfo = CommonDAL <LeaveInfo> .GetSingleObject(conditions);

            // Update the leave info
            testLeaveInfo.Reason = "Update test leave reason";
            try
            {
                testLeaveInfo.Save();
            }
            catch
            {
                Console.WriteLine("Throw exception for transact unit test");
            }

            // Get the updated leave info
            LeaveInfo updatedLeaveInfo = CommonDAL <LeaveInfo> .GetSingleObject(conditions);

            Assert.AreNotEqual(testLeaveInfo.Reason, updatedLeaveInfo.Reason);

            // Delete the leave, leave type, employees and roles
            leaveInfo.Delete();
            leaveType.Delete();
            employee.Delete();
            manager.Delete();
            employeeRole.Delete();
            managerRole.Delete();
        }
Beispiel #14
0
        public void TestDeleteEmployeeLeaveSummaryByApproveLeave()
        {
            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive          = true;
            employee.ServiceYears      = 10;
            employee.FKReportManagerID = managerGuid;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime  = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime    = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo   = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            DateTime                durationStartTime2 = Convert.ToDateTime("02/02/2011");
            DateTime                durationEndTime2   = Convert.ToDateTime("02/05/2011");
            TimeDurationInfo        timeDurationInfo2  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2);
            List <TimeDurationInfo> timeDurationList   = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);
            timeDurationList.Add(timeDurationInfo2);
            int leaveHours = CommonMethods.ComputeHours(timeDurationList);

            LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList);

            // Approve the applying leave.
            LeaveBLL.ApproveLeave(managerGuid.ToString(), leave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted);


            // Get the inserted employee leave summary
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("FKEmployeeID", employeeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            conditions.Add(SearchCondition.CreateSearchCondition("FKLeaveTypeID", leaveTypeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            EmployeeLeaveSummary employeeLeaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions);

            // Apply another leave
            DateTime                durationStartTime3 = DateTime.Parse("03/04/2011");
            DateTime                durationEndtime3   = DateTime.Parse("03/08/2011");
            TimeDurationInfo        timeDurationInfo3  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime3, durationEndtime3);
            DateTime                durationStartTime4 = DateTime.Parse("03/10/2011");
            DateTime                durationEndtime4   = DateTime.Parse("03/11/2011");
            TimeDurationInfo        timeDurationInfo4  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime4, durationEndtime4);
            List <TimeDurationInfo> timeDurationList2  = new List <TimeDurationInfo>();

            timeDurationList2.Add(timeDurationInfo3);
            timeDurationList2.Add(timeDurationInfo4);
            int newLeaveHours = CommonMethods.ComputeHours(timeDurationList2);

            LeaveInfo newLeave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "New Leave", leaveType.Name, "New Leave Desc", timeDurationList2);
            LeaveInfo delLeave = LeaveBLL.ApproveLeave(managerGuid.ToString(), newLeave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted);

            delLeave.Delete();

            // Get the update leave summary
            EmployeeLeaveSummary updatedLeaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions);

            Assert.AreEqual(updatedLeaveSummary.UsedHours, leaveHours);

            // Delete inserted items
            employeeLeaveSummary.Delete();
            leave.Delete();
            leaveType.Delete();
            employee.Delete();
            manager.Delete();
            managerRole.Delete();
            role.Delete();
        }
Beispiel #15
0
        private void btnGenerateTestData_Click(object sender, EventArgs e)
        {
            #region Delete Data First
            DeleteData();
            #endregion

            int         countEmployee = 0;
            int         countLeave    = 0;
            List <Guid> managerIDs    = new List <Guid>();

            #region Check Input
            if (!Int32.TryParse(txtCountEmployee.Text, out countEmployee))
            {
                MessageBox.Show("Count of Employees must be a number.");
                return;
            }

            if (!Int32.TryParse(txtCountLeave.Text, out countLeave))
            {
                MessageBox.Show("Count of level records for each employee must be a number.");
                return;
            }

            // we don't have more than 200 employees in BJ office.
            if (countEmployee > 200 || countEmployee < 1)
            {
                MessageBox.Show("We don't have more than 200 employees in BJ office.\r\nCount of Employees must >=1 and <201.");
                return;
            }

            // each employee can ask 150 leaves for a year? don't believe so
            if (countLeave > 150 || countLeave < 0)
            {
                MessageBox.Show("Each employee can ask 150 leaves for a year? Don't believe so.\r\nCount of level records for each employee must >=0 and <151.");
                return;
            }
            #endregion

            #region Add Role - Manager/Admin/Employee
            WriteLog("<< TEST DATA >>\r\n");
            WriteLog("\r\n==Roles==\r\n");
            // Stanley add: Our Real data is "Admin"/"Manager" and "Employee"
            string strManagerRole = "Manager";
            Role   roleManager    = Role.CreateRole(strManagerRole);
            roleManager.Save();
            //List<EmployeeRoleRL> employeeRoleList_Manager = new List<EmployeeRoleRL>();
            //employeeRoleList_Manager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID));
            WriteLog("Role: Manager\r\n");

            // Stanley add: Our Real data is "Admin"/"Manager" and "Employee"
            string strAdminRole = "Admin";
            Role   roleAdmin    = Role.CreateRole(strAdminRole);
            roleAdmin.Save();
            //List<EmployeeRoleRL> employeeRoleList_Admin = new List<EmployeeRoleRL>();
            //employeeRoleList_Admin.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID));
            WriteLog("Role: Admin\r\n");

            // Stanley add: Our Real data is "Admin"/"Manager" and "Employee"
            string strEmployeeRole = "Employee";
            Role   roleEmployee    = Role.CreateRole(strEmployeeRole);
            roleEmployee.Save();
            //List<EmployeeRoleRL> employeeRoleList_Employee = new List<EmployeeRoleRL>();
            //employeeRoleList_Employee.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID));
            WriteLog("Role: Employee\r\n");
            #endregion

            #region Add Leave Type, 7 types actually

            /**
             * Annual Leave
             * Bereavement Leave
             * Marriage Leave
             * Maternity Leave
             * Paternity Leave
             * Regular Check
             * Sick Leave
             */
            WriteLog("\r\n==Leave Types==\r\n");
            string    leave_Annual     = "Annual Leave";
            LeaveType leaveType_Annual = LeaveType.CreateLeaveType(leave_Annual,
                                                                   120,
                                                                   Convert.ToDateTime("1/1/2010"),
                                                                   Convert.ToDateTime("1/1/2011"));
            leaveType_Annual.Save();
            WriteLog("\r\nLeave Type: Annual Leave\r\n");

            string    leave_Sick     = "Sick Leave";
            LeaveType leaveType_Sick = LeaveType.CreateLeaveType(leave_Sick,
                                                                 80,
                                                                 Convert.ToDateTime("1/1/2010"),
                                                                 Convert.ToDateTime("1/1/2011"));
            leaveType_Sick.Save();
            WriteLog("Leave Type: Sick Leave\r\n");

            string    leave_Marriage     = "Marriage Leave";
            LeaveType leaveType_Marriage = LeaveType.CreateLeaveType(leave_Marriage,
                                                                     80,
                                                                     Convert.ToDateTime("1/1/2010"),
                                                                     Convert.ToDateTime("1/1/2011"));
            leaveType_Marriage.Save();
            WriteLog("Leave Type: Marriage Leave\r\n");

            // only for female
            string    leave_Maternity     = "Maternity Leave";
            LeaveType leaveType_Maternity = LeaveType.CreateLeaveType(leave_Maternity,
                                                                      960,
                                                                      Convert.ToDateTime("1/1/2010"),
                                                                      Convert.ToDateTime("1/1/2011"));
            leaveType_Maternity.Save();
            WriteLog("Leave Type: Maternity Leave\r\n");

            // only for male
            string    leave_Paternity     = "Paternity Leave";
            LeaveType leaveType_Paternity = LeaveType.CreateLeaveType(leave_Paternity,
                                                                      40,
                                                                      Convert.ToDateTime("1/1/2010"),
                                                                      Convert.ToDateTime("1/1/2011"));
            leaveType_Paternity.Save();
            WriteLog("Leave Type: Paternity Leave\r\n");

            // only for female
            string    leave_RegularCheck     = "Regular Check Leave";
            LeaveType leaveType_RegularCheck = LeaveType.CreateLeaveType(leave_RegularCheck,
                                                                         80,
                                                                         Convert.ToDateTime("1/1/2010"),
                                                                         Convert.ToDateTime("1/1/2011"));
            leaveType_RegularCheck.Save();
            WriteLog("Leave Type: Regular Check Leave\r\n");

            string    leave_Bereavement     = "Bereavement Leave";
            LeaveType leaveType_Bereavement = LeaveType.CreateLeaveType(leave_Bereavement,
                                                                        80,
                                                                        Convert.ToDateTime("1/1/2010"),
                                                                        Convert.ToDateTime("1/1/2011"));
            leaveType_Bereavement.Save();
            WriteLog("Leave Type: Bereavement Leave\r\n");
            #endregion

            #region Add a default (root) manager, it's rchou or hniu actually, here using rchou as example.
            Employee rootManager = Employee.CreateEmployee("*****@*****.**",
                                                           CryptographyStuff.AES_EncryptString("1234"),
                                                           Sex.Male,
                                                           "Richard",
                                                           Convert.ToDateTime("1/1/2001"),
                                                           "Chou");
            List <EmployeeRoleRL> employeeRoleList_RootManager = new List <EmployeeRoleRL>();
            employeeRoleList_RootManager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID));
            employeeRoleList_RootManager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID));
            employeeRoleList_RootManager.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID));
            rootManager.SetRoleList(employeeRoleList_RootManager);             // manager & admin & employee
            rootManager.IsActive = true;
            rootManager.Save();
            rootManager.IsAdmin = rootManager.IsManager = true;
            managerIDs.Add(rootManager.PKEmployeeID);             // managerIDs[0] is rchou's GUID

            WriteLog("\r\n==Test data of Users==\r\n");
            WriteLog("=====================================================================\r\n");
            WriteLog("Name\t\tIsManager\tIsAdmin\tBelong to\tLeave Counts\r\n");
            WriteLog("=====================================================================\r\n");
            WriteLog(rootManager.Email.Replace("@Advent.com", "") + "\t\t" + rootManager.IsManager.ToString() + "\t\t" + rootManager.IsAdmin.ToString() + "\t \t\t0\r\n");
            WriteLog("---------------------------------------------------------------------\r\n");
            #endregion

            #region As Shan said, create two test accounts, Admin(super-user) and Manager.
            // test account [email protected] (admin and manager)
            Employee adminAccount = Employee.CreateEmployee("*****@*****.**",
                                                            CryptographyStuff.AES_EncryptString("1234"),
                                                            Sex.Female,
                                                            "Admin",
                                                            Convert.ToDateTime("1/1/2001"),
                                                            "Test");
            List <EmployeeRoleRL> adminRoleList_EmployeeAccount = new List <EmployeeRoleRL>();
            adminRoleList_EmployeeAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID));
            adminRoleList_EmployeeAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID));
            adminRoleList_EmployeeAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID));
            adminAccount.SetRoleList(adminRoleList_EmployeeAccount);             // admin, manager and employee
            adminAccount.IsActive          = true;
            adminAccount.FKReportManagerID = rootManager.PKEmployeeID;           // report to Richard
            adminAccount.Save();
            adminAccount.IsAdmin = adminAccount.IsManager = true;
            managerIDs.Add(adminAccount.PKEmployeeID);             // managerIDs[1] is testAdmin's GUID
            WriteLog(adminAccount.Email.Replace("@Advent.com", "") + "\t\t" + adminAccount.IsManager.ToString() + "\t\t" + adminAccount.IsAdmin.ToString() + "\t" + rootManager.Email.Replace("@Advent.com", "") + "\t\t");
            WriteLog("0\r\n");
            WriteLog("---------------------------------------------------------------------\r\n");

            // test account [email protected]
            Employee managerAccount = Employee.CreateEmployee("*****@*****.**",
                                                              CryptographyStuff.AES_EncryptString("1234"),
                                                              Sex.Male,
                                                              "Manager",
                                                              Convert.ToDateTime("1/1/2001"),
                                                              "Test");
            List <EmployeeRoleRL> employeeRoleList_ManagerAccount = new List <EmployeeRoleRL>();
            employeeRoleList_ManagerAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID));
            employeeRoleList_ManagerAccount.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID));
            managerAccount.SetRoleList(employeeRoleList_ManagerAccount);             // manager & employee
            managerAccount.IsActive          = true;
            managerAccount.FKReportManagerID = adminAccount.PKEmployeeID;            // report to admin
            managerAccount.Save();
            managerAccount.IsManager = true;
            managerIDs.Add(managerAccount.PKEmployeeID);             // managerIDs[2] is testManager's GUID
            WriteLog(managerAccount.Email.Replace("@Advent.com", "") + "\t\t" + managerAccount.IsManager.ToString() + "\t\t" + managerAccount.IsAdmin.ToString() + "\t" + adminAccount.Email.Replace("@Advent.com", "") + "\t\t");
            WriteLog("0\r\n");
            WriteLog("---------------------------------------------------------------------\r\n");
            #endregion

            #region Create an employee randomlly
            int    index        = 0;
            string employeeName = "";
            Sex    sex          = Sex.Male;
            // create employees (admins and managers)
            while (countEmployee > 0)
            {
                bool   isAdmin   = false;
                bool   isManager = false;
                Random random    = new Random((int)DateTime.Now.Ticks);
                index++;
                List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();
                switch ((index - 1) % 6)                 // many employees, few admins and managers
                {
                case 0:
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleManager.PKRoleID));
                    employeeName = "m" + index.ToString("000") + "@Advent.com";
                    isManager    = true;
                    break;

                case 1:
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleAdmin.PKRoleID));
                    employeeName = "a" + index.ToString("000") + "@Advent.com";
                    isAdmin      = true;
                    break;

                case 2:
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID));
                    employeeName = "e" + index.ToString("000") + "@Advent.com";
                    break;

                default:
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, roleEmployee.PKRoleID));
                    employeeName = "e" + index.ToString("000") + "@Advent.com";
                    break;
                }

                if (random.Next(100) % 3 == 0)
                {
                    sex = Sex.Female;                                             // 1/3 people are female
                }
                int      tempDay  = -random.Next(30, 720);
                Employee employee = Employee.CreateEmployee(employeeName,
                                                            CryptographyStuff.AES_EncryptString("1234"),
                                                            sex,                                                             //Sex.Male,
                                                            string.Format(newFirstName, index.ToString("000")) + employeeName[0],
                                                            DateTime.Now.AddDays(tempDay),
                                                            string.Format(newLastName, index.ToString("000")) + employeeName[0]);
                employee.SetRoleList(employeeRoleList);
                employee.IsActive = true;
                if (employeeName.StartsWith("m"))                 // a manager
                {
                    employee.FKReportManagerID = managerIDs[0];   // manager reports to root manager
                }
                else if (employeeName.StartsWith("a"))            // a admin
                {
                    employee.FKReportManagerID = managerIDs[0];   // admin reports to root manager
                }
                else
                {
                    Random randomTemp = new Random((int)DateTime.Now.Ticks);
                    if (managerIDs.Count == 1)
                    {
                        employee.FKReportManagerID = managerIDs[0];                         // only have one manager
                    }
                    else if (managerIDs.Count == 2)
                    {
                        employee.FKReportManagerID = managerIDs[1];                         // normally, others employees belong to a normal manager, not root manager
                    }
                    else
                    {
                        int tempIndex = randomTemp.Next(1, managerIDs.Count - 1);
                        employee.FKReportManagerID = managerIDs[tempIndex];
                    }
                }
                employee.Save();
                employee.IsManager = isManager;
                employee.IsAdmin   = isAdmin;
                Employee tempManager = EmployeeBLL.GetEmployeeByID(employee.FKReportManagerID.ToString());
                WriteLog(employee.Email.Replace("@Advent.com", "") + "\t\t" + employee.IsManager.ToString() + "\t\t" + employee.IsAdmin.ToString() + "\t" + tempManager.Email.Replace("@Advent.com", "") + "\t\t");

                // add manager to management team
                if (employeeName.StartsWith("m"))
                {
                    managerIDs.Add(employee.PKEmployeeID);
                }

                int count  = countLeave;
                int leaves = 0;
                while (count > 0)
                {
                    string name = string.Empty;
                    switch (random.Next(100) % 7)
                    {
                    case 0:
                        name = leave_Annual;
                        break;

                    case 1:
                        name = leave_Sick;
                        break;

                    case 2:
                        name = leave_Marriage;
                        break;

                    case 3:
                        name = leave_Bereavement;
                        break;

                    case 4:
                        name = leave_Maternity;
                        break;

                    case 5:
                        name = leave_Paternity;
                        break;

                    case 6:
                        name = leave_RegularCheck;
                        break;

                    default:
                        name = leave_Annual;
                        break;
                    }

                    #region Create Random TimeDurationInfo
                    Random randomForTimeDurationInfo         = new Random((int)DateTime.Now.Ticks);
                    List <TimeDurationInfo> timeDurationList = new List <TimeDurationInfo>();
                    for (int i = 0; i < randomForTimeDurationInfo.Next(5); i++)
                    {
                        DateTime durationStartTime = DateTime.Now;
                        DateTime durationEndTime   = DateTime.Now;
                        GenerateStartEndTime(ref durationStartTime, ref durationEndTime);
                        TimeDurationInfo timeDurationInfo = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
                        timeDurationList.Add(timeDurationInfo);
                    }
                    #endregion

                    if (timeDurationList.Count > 0)
                    {
                        LeaveBLL.ApplyLeave(employee.PKEmployeeID.ToString(), "generated automatically", name, "generated automatically", timeDurationList);
                        leaves++;
                    }

                    count--;
                }
                WriteLog(leaves.ToString() + "\r\n");
                WriteLog("---------------------------------------------------------------------\r\n");

                countEmployee--;
            }
            #endregion

            if (MessageBox.Show("Finished!") == System.Windows.Forms.DialogResult.OK)
            {
                Process.Start(logFile);
            }
        }
Beispiel #16
0
        private void btnGenerateData_Click(object sender, EventArgs e)
        {
            int countEmployee = Int32.Parse(txtCountEmployee.Text);
            int countLeave    = Int32.Parse(txtCountLeave.Text);

            string roleName1 = RoleRank.Admin.ToString();
            Role   role1     = Role.GetRoleByName(roleName1);

            if (null == role1)
            {
                role1 = Role.CreateRole(roleName1);
                role1.Save();
            }

            string roleName2 = RoleRank.Manager.ToString();
            Role   role2     = Role.GetRoleByName(roleName2);

            if (null == role2)
            {
                role2 = Role.CreateRole(roleName2);
                role2.Save();
            }

            string roleName3 = RoleRank.Employee.ToString();
            Role   role3     = Role.GetRoleByName(roleName3);

            if (null == role3)
            {
                role3 = Role.CreateRole(roleName3);
                role3.Save();
            }

            // Add a default manager.
            Employee manager = Employee.CreateEmployee(string.Format(emplyeeName, Guid.NewGuid().ToString().Substring(0, 5)),
                                                       CryptographyStuff.AES_EncryptString("1234"),
                                                       Sex.Male,
                                                       string.Format(firstName, Guid.NewGuid().ToString().Substring(0, 5)),
                                                       Convert.ToDateTime("1/1/2011"),
                                                       string.Format(lastName, Guid.NewGuid().ToString().Substring(0, 5)));
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role2.PKRoleID));
            manager.SetRoleList(employeeRoleList);
            manager.IsActive = true;
            manager.Save();
            Guid managerID = manager.PKEmployeeID;

            string    leaveTypeName1 = string.Format(leaveTypeName, Guid.NewGuid().ToString().Substring(0, 5));
            LeaveType leaveType1     = LeaveType.CreateLeaveType(leaveTypeName1,
                                                                 100,
                                                                 Convert.ToDateTime("1/1/2010"),
                                                                 Convert.ToDateTime("1/1/2011"));

            leaveType1.Save();

            string    leaveTypeName2 = string.Format(leaveTypeName, Guid.NewGuid().ToString().Substring(0, 5));
            LeaveType leaveType2     = LeaveType.CreateLeaveType(leaveTypeName2,
                                                                 100,
                                                                 Convert.ToDateTime("1/1/2010"),
                                                                 Convert.ToDateTime("1/1/2011"));

            leaveType2.Save();

            string    leaveTypeName3 = string.Format(leaveTypeName, Guid.NewGuid().ToString().Substring(0, 5));
            LeaveType leaveType3     = LeaveType.CreateLeaveType(leaveTypeName3,
                                                                 100,
                                                                 Convert.ToDateTime("1/1/2010"),
                                                                 Convert.ToDateTime("1/1/2011"));

            leaveType3.Save();

            DateTime durationStartTime  = Convert.ToDateTime("02/02/2001");
            DateTime durationEndTime    = Convert.ToDateTime("02/05/2001");
            DateTime durationStartTime2 = Convert.ToDateTime("02/02/2011");
            DateTime durationEndTime2   = Convert.ToDateTime("02/05/2011");

            while (countEmployee > 0)
            {
                employeeRoleList = new List <EmployeeRoleRL>();
                switch (countEmployee % 3)
                {
                case 0:
                    // Admin
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role1.PKRoleID));
                    break;

                case 1:
                    // Manager
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role2.PKRoleID));
                    break;

                case 2:
                    // Employee
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role3.PKRoleID));
                    break;

                default:
                    // Employee
                    employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role3.PKRoleID));
                    break;
                }

                Employee employee = Employee.CreateEmployee(string.Format(emplyeeName, Guid.NewGuid().ToString().Substring(0, 5)),
                                                            CryptographyStuff.AES_EncryptString("1234"),
                                                            Sex.Male,
                                                            string.Format(firstName, Guid.NewGuid().ToString().Substring(0, 5)),
                                                            Convert.ToDateTime("1/1/2011"),
                                                            string.Format(lastName, Guid.NewGuid().ToString().Substring(0, 5)));
                employee.SetRoleList(employeeRoleList);
                employee.IsActive          = true;
                employee.FKReportManagerID = managerID;
                employee.Save();

                // Set the manager id as the employee who is manager.
                if (countEmployee % 3 == 1)
                {
                    managerID = employee.PKEmployeeID;
                }

                int count = countLeave;
                while (count > 0)
                {
                    string name = string.Empty;
                    switch (countLeave % 3)
                    {
                    case 0:
                        name = leaveTypeName1;
                        break;

                    case 1:
                        name = leaveTypeName2;
                        break;

                    case 2:
                        name = leaveTypeName3;
                        break;

                    default:
                        name = leaveTypeName1;
                        break;
                    }

                    List <TimeDurationInfo> timeDurationList  = new List <TimeDurationInfo>();
                    TimeDurationInfo        timeDurationInfo  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
                    TimeDurationInfo        timeDurationInfo2 = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2);
                    timeDurationList.Add(timeDurationInfo);
                    timeDurationList.Add(timeDurationInfo2);

                    LeaveBLL.ApplyLeave(employee.PKEmployeeID.ToString(), "generated automatically", name, "generated automatically", timeDurationList);

                    count--;
                }

                countEmployee--;
            }

            MessageBox.Show("Finished!");
        }