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

TerminatingAtStation() public method

public TerminatingAtStation ( string crsCode, DateTime startDate, DateTime endDate, string atocCode = null, PowerType powerType = null ) : IEnumerable
crsCode string
startDate DateTime
endDate DateTime
atocCode string
powerType PowerType
return IEnumerable
        public IEnumerable<TrainMovementResult> TerminatingAtStation(string crsCode, DateTime? startDate, DateTime? endDate, 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 tiplocs = _tiplocRepository.GetAllByCRSCode(crsCode)
                .Select(t => t.TiplocId);

            if (!tiplocs.Any())
                return Enumerable.Empty<TrainMovementResult>();

            return TerminatingAt(tiplocs, startDate.Value, endDate.Value, atocCode, powerType);
        }