public WaitingApprovalTodayVisitor(int currentUserADId, int currentUserInfoId, string siteUrl) { FilterTaskList = new List <FilterTask>(); _currentUserADId = currentUserADId; _currentUserInfoId = currentUserInfoId; _siteUrl = siteUrl; _filterTaskManager = new FilterTaskManager(siteUrl); _shiftManagementDetailDAL = new ShiftManagementDetailDAL(siteUrl); }
private bool IsShiftApproved(int shiftId) { bool ret = true; ShiftManagementDetailDAL _shiftManagementDetailDAL = new ShiftManagementDetailDAL(SiteUrl); List <ShiftManagementDetail> shiftManagementDetails = _shiftManagementDetailDAL.GetByShiftManagementID(shiftId); if (shiftManagementDetails != null && shiftManagementDetails.Count > 0) { ShiftTimeDAL _shiftTimeDAL = new ShiftTimeDAL(SiteUrl); List <Biz.Models.ShiftTime> shiftTimes = _shiftTimeDAL.GetShiftTimes(); List <string> shiftCodeList = shiftTimes.Where(e => e.ShiftRequired == true).Select(e => e.Code.ToUpper()).ToList(); Type typeShiftManagementDetail = typeof(ShiftManagementDetail); BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public; foreach (var shiftManagementDetail in shiftManagementDetails) { if (ret == false) { break; } for (int idx = 1; idx <= 31; idx++) { PropertyInfo shiftTimeInfo = typeShiftManagementDetail.GetProperty(string.Format("ShiftTime{0}", idx), bindingFlags); object shiftTimeValue = shiftTimeInfo.GetValue(shiftManagementDetail, null); if (shiftTimeValue != null) { LookupItem shiftTimeValueObj = shiftTimeValue as LookupItem; if (!string.IsNullOrEmpty(shiftTimeValueObj.LookupValue) && shiftCodeList.Contains(shiftTimeValueObj.LookupValue)) { PropertyInfo shiftTimeApprovalInfo = typeShiftManagementDetail.GetProperty(string.Format("ShiftTime{0}Approval", idx), bindingFlags); object shiftTimeApprovalValue = shiftTimeApprovalInfo.GetValue(shiftManagementDetail, null); if (shiftTimeApprovalValue != null && Convert.ToBoolean(shiftTimeApprovalValue) == true) { ret = true; } else { ret = false; break; } } } } } } return(ret); }
public void ImportExcel() { ExcelShiftsOfDepartment excelShiftsOfDepartment = ReadExcelShiftData(); excelShiftsOfDepartment.DepartmentId = 2; //HR excelShiftsOfDepartment.Location = 2; excelShiftsOfDepartment.Month = 7; excelShiftsOfDepartment.Year = 2017; Dictionary <string, int> duplicatedEmployees = ValidateDuplicatedData(excelShiftsOfDepartment); string siteUrl = "http://rbvhspdev01:81/"; ShiftManagementDAL _shiftManagementDAL = new ShiftManagementDAL(siteUrl); ShiftManagementDetailDAL _shiftManagementDetailDAL = new ShiftManagementDetailDAL(siteUrl); List <ShiftManagement> shiftManagements = _shiftManagementDAL.GetByMonthYearDepartment(excelShiftsOfDepartment.Month, excelShiftsOfDepartment.Year, excelShiftsOfDepartment.DepartmentId, excelShiftsOfDepartment.Location); List <ShiftManagementDetail> shiftManagementDetails = new List <ShiftManagementDetail>(); if (shiftManagements != null && shiftManagements.Count > 0) { shiftManagementDetails = _shiftManagementDetailDAL.GetByShiftManagementID(shiftManagements[0].ID); } EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(siteUrl); List <EmployeeInfo> employeesOfDepartment = _employeeInfoDAL.GetByLocationAndDepartment(2, excelShiftsOfDepartment.DepartmentId, true, 4, StringConstant.EmployeeInfoList.EmployeeIDField); if (shiftManagementDetails != null && shiftManagementDetails.Count > 0) { foreach (var employeeShift in excelShiftsOfDepartment.EmployeeShifts) { EmployeeInfo employeeInfo = employeesOfDepartment.Where(e => e.EmployeeID == employeeShift.EmployeeID).FirstOrDefault(); if (employeeInfo != null) { employeeShift.EmployeeLookupID = employeeInfo.ID; } } List <int> employeeLookupIds = excelShiftsOfDepartment.EmployeeShifts.Select(e => e.EmployeeLookupID).ToList(); shiftManagementDetails = shiftManagementDetails.Where(e => employeeLookupIds.Contains(e.Employee.LookupId)).ToList(); } foreach (ExcelEmployeeShift excelEmployeeShift in excelShiftsOfDepartment.EmployeeShifts) { ShiftManagementDetail shiftManagementDetail = shiftManagementDetails.Where(e => e.Employee.LookupId == excelEmployeeShift.EmployeeLookupID).FirstOrDefault(); if (shiftManagementDetail == null) { shiftManagementDetail = new ShiftManagementDetail(); EmployeeInfo employeeInfo = employeesOfDepartment.Where(e => e.EmployeeID == excelEmployeeShift.EmployeeID).FirstOrDefault(); shiftManagementDetail.Employee = new LookupItem() { LookupId = employeeInfo.ID, LookupValue = employeeInfo.FullName }; shiftManagementDetails.Add(shiftManagementDetail); } ShiftTimeDAL _shiftTimeDAL = new ShiftTimeDAL(siteUrl); List <ShiftTime> shiftTimes = _shiftTimeDAL.GetAll(); for (int i = 0; i < 11; i++) { ShiftTime shiftTime = shiftTimes.Where(e => e.Code.ToUpper() == excelEmployeeShift.ShiftCodes[i].ToUpper()).FirstOrDefault(); if (shiftTime != null) { Type type = typeof(ShiftManagementDetail); PropertyInfo shiftApprovalInfo = type.GetProperty(string.Format("ShiftTime{0}Approval", i + 21)); object shiftApprovalValue = shiftApprovalInfo.GetValue(shiftManagementDetail, null); if (shiftApprovalValue != null && Convert.ToBoolean(shiftApprovalValue) == false) { PropertyInfo shiftInfo = type.GetProperty(string.Format("ShiftTime{0}", i + 21)); LookupItem shiftValue = shiftInfo.GetValue(shiftManagementDetail, null) as LookupItem; if (shiftValue == null) { shiftValue = new LookupItem(); } shiftValue.LookupId = shiftTime.ID; shiftValue.LookupValue = shiftTime.Code; } } } for (int i = 11; i < 31; i++) { ShiftTime shiftTime = shiftTimes.Where(e => e.Code.ToUpper() == excelEmployeeShift.ShiftCodes[i].ToUpper()).FirstOrDefault(); if (shiftTime != null) { Type type = typeof(ShiftManagementDetail); PropertyInfo shiftApprovalInfo = type.GetProperty(string.Format("ShiftTime{0}Approval", i - 10)); object shiftApprovalValue = shiftApprovalInfo.GetValue(shiftManagementDetail, null); if (shiftApprovalValue != null && Convert.ToBoolean(shiftApprovalValue) == false) { PropertyInfo shiftInfo = type.GetProperty(string.Format("ShiftTime{0}", i - 10)); LookupItem shiftValue = shiftInfo.GetValue(shiftManagementDetail, null) as LookupItem; if (shiftValue == null) { shiftValue = new LookupItem(); } shiftValue.LookupId = shiftTime.ID; shiftValue.LookupValue = shiftTime.Code; } } } } int shiftId = 0; if (shiftManagements == null || shiftManagements.Count == 0) { Biz.Models.ShiftManagement shiftManagement = new Biz.Models.ShiftManagement(); shiftManagement.Department = new LookupItem() { LookupId = excelShiftsOfDepartment.DepartmentId, LookupValue = excelShiftsOfDepartment.DepartmentId.ToString() }; shiftManagement.Location = new LookupItem() { LookupId = excelShiftsOfDepartment.Location, LookupValue = excelShiftsOfDepartment.Location.ToString() }; shiftManagement.Month = excelShiftsOfDepartment.Month; shiftManagement.Year = excelShiftsOfDepartment.Year; EmployeeInfo requester = _employeeInfoDAL.GetByADAccount(122); shiftManagement.Requester = new LookupItem() { LookupId = requester.ID, LookupValue = requester.FullName }; EmployeeInfo approvedBy = _employeeInfoDAL.GetByPositionDepartment(StringConstant.EmployeePosition.DepartmentHead, excelShiftsOfDepartment.DepartmentId, excelShiftsOfDepartment.Location).FirstOrDefault(); shiftManagement.ApprovedBy = new User() { ID = approvedBy.ADAccount.ID, UserName = approvedBy.ADAccount.UserName, FullName = approvedBy.FullName, IsGroup = false }; shiftId = _shiftManagementDAL.SaveOrUpdate(shiftManagement); } else { shiftId = shiftManagements[0].ID; } if (shiftId > 0) { foreach (ShiftManagementDetail shiftManagementDetail in shiftManagementDetails) { shiftManagementDetail.ShiftManagementID = new LookupItem() { LookupId = shiftId, LookupValue = shiftId.ToString() }; int shiftDetailId = _shiftManagementDetailDAL.SaveOrUpdate(shiftManagementDetail); } } }
public ShiftTimeDAL(string siteUrl) : base(siteUrl) { ListUrl = "/Lists/ShiftTime"; _shiftManagementDAL = new ShiftManagementDAL(siteUrl); ShiftManagementDetailDAL = new ShiftManagementDetailDAL(siteUrl); }