TrainNotifier.Service.TrainMovementRepository.GetRunningTerminatingAtSchedules C# (CSharp) Method

GetRunningTerminatingAtSchedules() private method

private GetRunningTerminatingAtSchedules ( IEnumerable tiplocs, System.DateTime date, System.TimeSpan startTime, System.TimeSpan endTime, string atocCode, PowerType powerType ) : IEnumerable
tiplocs IEnumerable
date System.DateTime
startTime System.TimeSpan
endTime System.TimeSpan
atocCode string
powerType PowerType
return IEnumerable
        private IEnumerable<ScheduleHolder> GetRunningTerminatingAtSchedules(IEnumerable<short> tiplocs, DateTime date, TimeSpan startTime, TimeSpan endTime, string atocCode, PowerType? powerType)
        {
            if (!tiplocs.Any())
                return Enumerable.Empty<ScheduleHolder>();

            const string getSchedulesSql = @"
                SELECT [ScheduleTrain].[ScheduleId]
                    ,[ScheduleTrain].[TrainUid]
                    ,[ScheduleTrain].[STPIndicatorId]
                FROM [ScheduleTrain]
                INNER JOIN [ScheduleTrainStop] ON [ScheduleTrain].[ScheduleId] = [ScheduleTrainStop].[ScheduleId]
                WHERE [ScheduleTrainStop].[Terminate] = 1
                    AND [ScheduleTrainStop].[TiplocId] IN @tiplocs
                    AND [ScheduleTrain].[DestinationStopTiplocId] IN @tiplocs
                    AND [ScheduleTrain].[Runs{0}] = 1
                    AND @date >= [ScheduleTrain].[StartDate]
                    AND @date <= [ScheduleTrain].[EndDate]
                    AND COALESCE(Arrival, Departure, Pass) >= @startTime
                    AND COALESCE(Arrival, Departure, Pass) < @endTime
                    AND [ScheduleTrain].[Deleted] = 0{1}{2}
                    ORDER BY COALESCE(Arrival, Departure, Pass)";

            return Query<ScheduleHolder>(string.Format(getSchedulesSql,
                date.DayOfWeek,
                (!string.IsNullOrEmpty(atocCode) ? _atocCodeFilter : string.Empty),
                (powerType.HasValue ? _powerTypeFilter : string.Empty)), new
                {
                    tiplocs,
                    date = date.Date,
                    startTime,
                    endTime,
                    atocCode,
                    powerType
                });
        }