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

CallingBetweenStations() public method

public CallingBetweenStations ( string fromCrs, string toCrs, System.DateTime startDate = null, System.DateTime endDate = null, string atocCode = null, PowerType powerType = null ) : IEnumerable
fromCrs string
toCrs string
startDate System.DateTime
endDate System.DateTime
atocCode string
powerType PowerType
return IEnumerable
        public IEnumerable<TrainMovementResult> CallingBetweenStations(string fromCrs, string toCrs, DateTime? startDate = null, DateTime? endDate = null, string atocCode = null, PowerType? powerType = null)
        {
            startDate = startDate ?? DateTime.UtcNow.AddDays(-1);
            endDate = endDate ?? DateTime.UtcNow.Date.Add(new TimeSpan(23, 59, 59));

            if ((endDate.Value - startDate.Value) > TimeSpan.FromDays(1))
            {
                endDate = startDate.Value.AddDays(1);
            }

            // get tiploc id to improve query
            var tiplocsFrom = _tiplocRepository.GetAllByCRSCode(fromCrs)
                .Select(t => t.TiplocId);
            var tiplocsTo = _tiplocRepository.GetAllByCRSCode(toCrs)
                .Select(t => t.TiplocId);

            if (!tiplocsFrom.Any() || !tiplocsTo.Any())
                return Enumerable.Empty<TrainMovementResult>();

            return CallingBetween(tiplocsFrom, tiplocsTo, startDate.Value, endDate.Value, atocCode, powerType);
        }