/// <summary> /// Get my leaves /// </summary> /// <param name="employeeID">GUID of current employee</param> /// <returns>List of leaves</returns> public List <LeaveInfo> GetMyLeaves(string employeeID) { Log.Info(GlobalParams.StartGetPersonalLeaves); List <LeaveInfo> leaves = null; try { leaves = LeaveBLL.GetMyLeaves(employeeID, new DateTime(DateTime.Now.Year, 1, 1), DateTime.MaxValue); } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndGetPersonalLeaves); return(leaves); }
public void TestGetMyLeaves() { // 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.GetMyLeaves(employee.PKEmployeeID.ToString()); // 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(); }