コード例 #1
0
        public static LeaveInfo ApplyLeave(string employeeID, string reason, string leaveType, string description, List <TimeDurationInfo> durationList)
        {
            LeaveInfo leaveInfo = null;

            if (!string.IsNullOrEmpty(employeeID) && !string.IsNullOrEmpty(reason) && !string.IsNullOrEmpty(leaveType) && null != durationList)
            {
                Employee employee = EmployeeBLL.GetEmployeeByID(employeeID);
                if (null != employee)
                {
                    if (employee.Manager == null)
                    {
                        throw new Exception("You didn't set supervisor to approve your leave application.");
                    }

                    List <SearchCondition> conditions = new List <SearchCondition>();
                    conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Name, leaveType, SearchComparator.Equal, SearchType.SearchString));
                    LeaveType lType = CommonDAL <LeaveType> .GetSingleObject(conditions);

                    leaveInfo =
                        LeaveInfo.CreateLeaveInfo(employee.PKEmployeeID, employee.FKReportManagerID, lType.PKLeaveTypeID,
                                                  LeaveStatus.Applying, reason, description, durationList);
                    leaveInfo.Save();

                    conditions.Clear();
                    conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.PKLeaveTypeID, leaveInfo.FKLeaveTypeID.ToString(), SearchComparator.Equal, SearchType.SearchString));
                    leaveInfo.Type = CommonDAL <LeaveType> .GetSingleObject(conditions);
                }
            }

            return(leaveInfo);
        }
コード例 #2
0
        public static LeaveInfo ApproveLeave(string managerID, string leaveID, LeaveStatus status)
        {
            LeaveInfo leave = null;

            if (!string.IsNullOrEmpty(managerID) && !string.IsNullOrEmpty(leaveID) && status != LeaveStatus.None)
            {
                leave = LeaveBLL.GetLeaveInfoByID(leaveID);
                leave.FKReportManagerID = Guid.Parse(managerID);
                leave.PreStatus         = leave.Status;         // get previous status
                leave.Status            = status;
                leave.Save();
            }

            return(leave);
        }
コード例 #3
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();
        }
コード例 #4
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();
        }