public ShiftDay GetShiftDayforDateTime(DateTime timestamp) { if (Days != null && Days.Any() && Department != null) { var shiftStart = StartTime; if (String.IsNullOrWhiteSpace(shiftStart)) { shiftStart = "12:00 AM"; } var shiftDays = from sd in Days let shiftDayTime = DateTimeHelpers.ConvertStringTime(shiftStart, sd.Day, Department.Use24HourTime.GetValueOrDefault()) let shiftDayToCheck = timestamp.TimeConverter(Department) where shiftDayTime == shiftDayToCheck.Within(TimeSpan.FromMinutes(15)) select sd; if (shiftDays != null) { return(shiftDays.FirstOrDefault()); } } return(null); }
public List <ShiftDay> GetShiftDaysForDay(DateTime currentTime, int departmentId) { var shiftDays = new List <ShiftDay>(); var shifts = (from s in _shiftsRepository.GetAll() where s.DepartmentId == departmentId select s).ToList(); foreach (var shift in shifts) { var localizedDate = TimeConverterHelper.TimeConverter(currentTime, shift.Department); var shiftStart = shift.StartTime; if (String.IsNullOrWhiteSpace(shiftStart)) { shiftStart = "12:00 AM"; } var startTime = DateTimeHelpers.ConvertStringTime(shiftStart, localizedDate, shift.Department.Use24HourTime.GetValueOrDefault()); var days = from sd in shift.Days let shiftDayTime = DateTimeHelpers.ConvertStringTime(shiftStart, sd.Day, shift.Department.Use24HourTime.GetValueOrDefault()) let nextDayShiftTime = localizedDate where shiftDayTime == nextDayShiftTime.Within(TimeSpan.FromHours(12)) select sd; shiftDays.AddRange(days); } return(shiftDays); }
public async Task <List <ShiftDay> > GetShiftDaysForDayAsync(DateTime currentTime, int departmentId) { var shiftDays = new List <ShiftDay>(); var shifts = await _shiftsRepository.GetAllByDepartmentIdAsync(departmentId); var department = await _departmentsService.GetDepartmentByIdAsync(departmentId, false); foreach (var shift in shifts) { shift.Days = new List <ShiftDay>(await _shiftDaysRepository.GetAllShiftDaysByShiftIdAsync(shift.ShiftId)); var localizedDate = currentTime.TimeConverter(department); var shiftStart = shift.StartTime; if (String.IsNullOrWhiteSpace(shiftStart)) { shiftStart = "12:00 AM"; } var startTime = DateTimeHelpers.ConvertStringTime(shiftStart, localizedDate, department.Use24HourTime.GetValueOrDefault()); var days = from sd in shift.Days let shiftDayTime = DateTimeHelpers.ConvertStringTime(shiftStart, sd.Day, department.Use24HourTime.GetValueOrDefault()) let nextDayShiftTime = localizedDate where shiftDayTime == nextDayShiftTime.Within(TimeSpan.FromHours(12)) select sd; shiftDays.AddRange(days); } return(shiftDays); }
public List <Shift> GetShiftsStartingNextDay(DateTime currentTime) { var upcomingShifts = new List <Shift>(); var shifts = _shiftsRepository.GetAllShiftsAndDays(); foreach (var shift in shifts) { try { var localizedDate = TimeConverterHelper.TimeConverter(currentTime, shift.Department); var shiftStart = shift.StartTime; if (String.IsNullOrWhiteSpace(shiftStart)) { shiftStart = "12:00 AM"; } var startTime = DateTimeHelpers.ConvertStringTime(shiftStart, localizedDate, shift.Department.Use24HourTime.GetValueOrDefault()); var shiftDays = from sd in shift.Days let shiftDayTime = DateTimeHelpers.ConvertStringTime(shiftStart, sd.Day, shift.Department.Use24HourTime.GetValueOrDefault()) let nextDayShiftTime = localizedDate.AddDays(1) where shiftDayTime == nextDayShiftTime.Within(TimeSpan.FromMinutes(15)) select sd; //List<ShiftDay> shiftDays = new List<ShiftDay>(); //foreach (var sd in shift.Days) //{ // var shiftDayTime = DateTimeHelpers.ConvertStringTime(shiftStart, sd.Day, shift.Department.Use24HourTime.GetValueOrDefault()); // var nextDayShiftTime = localizedDate.AddDays(1); // if (shiftDayTime == nextDayShiftTime.Within(TimeSpan.FromMinutes(15))) // shiftDays.Add(sd); //} if (shiftDays.Any()) { var previousShift = from sd in shift.Days where sd.Day.ToShortDateString() == startTime.ToShortDateString() select sd; if (!previousShift.Any()) { upcomingShifts.Add(shift); } } } catch (Exception ex) { Logging.LogException(ex, $"DepartmentId:{shift.DepartmentId}"); } } return(upcomingShifts); }
public List <Shift> GetShiftsStartingNextDay(DateTime currentTime) { var upcomingShifts = new List <Shift>(); var shifts = (from s in _shiftsRepository.GetAll() select s).ToList(); foreach (var shift in shifts) { var localizedDate = TimeConverterHelper.TimeConverter(currentTime, shift.Department); var shiftStart = shift.StartTime; if (String.IsNullOrWhiteSpace(shiftStart)) { shiftStart = "12:00 AM"; } var startTime = DateTimeHelpers.ConvertStringTime(shiftStart, localizedDate, shift.Department.Use24HourTime.GetValueOrDefault()); var shiftDays = from sd in shift.Days let shiftDayTime = DateTimeHelpers.ConvertStringTime(shiftStart, sd.Day, shift.Department.Use24HourTime.GetValueOrDefault()) let nextDayShiftTime = localizedDate.AddDays(1) where shiftDayTime == nextDayShiftTime.Within(TimeSpan.FromMinutes(15)) select sd; if (shiftDays.Any()) { var previousShift = from sd in shift.Days where sd.Day.ToShortDateString() == startTime.ToShortDateString() select sd; if (!previousShift.Any()) { upcomingShifts.Add(shift); } } } return(upcomingShifts); }