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); }
public BaseResponse <LeaveInfo> EditLeave(LeaveInfoEditRequest info) { info.User = UserManager.getUserById(User.Identity.Name); if (string.IsNullOrEmpty(info.Id)) { var result = LeaveInfo.CreateLeaveInfo(info); UserLog.create("请假申请已创建", "请假申请", info.User, result); return(BaseResponse.getResult(result, "创建成功")); } else { var leaveInfo = new LeaveInfo(info.Id); //这里可进行一些判断例如状态判断什么的 if (leaveInfo.OrderStatus == monkey.service.WorkFlow.WorkOrderStatus.待提交 || leaveInfo.OrderStatus == monkey.service.WorkFlow.WorkOrderStatus.已终止) { var result = leaveInfo.EditLeaveInfo(info); UserLog.create("请假申请被重新编辑", "请假申请", info.User, result); return(BaseResponse.getResult(result, "保存成功")); } else { throw new ValiDataException(string.Format("状态为[{0}]的请假申请不能被编辑", leaveInfo.OrderStatusString)); } } }
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(); }
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(); }