Untitled
public ImportReaderViewModel<Timelogs, ValidationResult> TimelogAIS(List<TimelogsToPayDay> aisLogDatas) { var validEntities = new List<Timelogs>(); var validationErrors = new List<ValidationResult>(); List<Timelogs> timelogsToInsert = new List<Timelogs>(); // get all employee201 from Alliance Software var employeeDataList = _employeeRepository.GetAllEmployeeAIS(); foreach (var aisLogData in aisLogDatas) { Timelogs tempLog = new Timelogs(); var getEmployeeDetails = employeeDataList.Find(x => x.EmployeeID == aisLogData.EmployeeID); if(getEmployeeDetails == null) { continue; } tempLog.EmployeeID = getEmployeeDetails.ID; tempLog.TimelogDate = aisLogData.TimelogDate; tempLog.Employee = getEmployeeDetails; tempLog.TimeIn = aisLogData.Timein.HasValue ? aisLogData.Timein : null; tempLog.TimeOut = aisLogData.Timeout.HasValue ? aisLogData.Timeout : null; tempLog.TimelogError = aisLogData.Timein.HasValue && aisLogData.Timeout.HasValue ? null : Constants.Timelogs.Error.InOut; timelogsToInsert.Add(tempLog); } if (timelogsToInsert.Count > 0) { foreach (var timelog in timelogsToInsert) { var dbEmployee = _employeeRepository.FindByID(timelog.EmployeeID); if (dbEmployee == null) { validationErrors.Add(new ValidationResult(string.Format(Constants.Common.RecordNotExistWithLine))); } else if (IsEmployeeSuspended(timelog.TimelogDate, dbEmployee.ID)) { validationErrors.Add(new ValidationResult(string.Format(Constants.Timelogs.SuspendLogImport))); } else { // passed either timein date or timeout date value var timelogDate = TimelogsHandler.GetShiftSchedLogDate(timelog); if (dbEmployee.UserMaster.ShiftID.HasValue) { var hasShiftSchedule = HasEmployeeShiftSchedule(dbEmployee.UserMaster.ShiftID.Value, timelogDate); if (!hasShiftSchedule) { validationErrors.Add(new ValidationResult(string.Format(Constants.Common.NoShiftScheduleWithLine, timelog.TimelogID))); } else { var getEmployeeShiftSched = GetTimelogShiftSchedule(dbEmployee.UserMaster.ShiftID.Value, timelogDate); timelog.ShiftTimeIn = getEmployeeShiftSched.TimeIn.Value; timelog.ShiftBreakStart = getEmployeeShiftSched.BreakStart.Value; timelog.ShiftBreakEnd = getEmployeeShiftSched.BreakEnd.Value; timelog.ShiftTimeOut = getEmployeeShiftSched.TimeOut.Value; timelog.ShiftCutOff = getEmployeeShiftSched.CutOff.Value; timelog.ShiftID = dbEmployee.UserMaster.ShiftID.Value; validEntities.Add(timelog); } } else { validationErrors.Add(new ValidationResult(string.Format(Constants.Common.NoShiftScheduleWithLine, timelog.TimelogID))); } } } } return new ImportReaderViewModel<Timelogs, ValidationResult> { SucceededReadLines = validEntities, FailedReadLines = validationErrors }; } }
Leave a Comment