diff --git a/02_ProjectOrientedSessions/Session04/Session04.md b/02_ProjectOrientedSessions/Session04/Session04.md index f7a8312..7f99f61 100644 --- a/02_ProjectOrientedSessions/Session04/Session04.md +++ b/02_ProjectOrientedSessions/Session04/Session04.md @@ -74,34 +74,37 @@ public interface ITransportationRepository : IRepository 📂 Suggested Folder: Infrastructure/Services/Services/TransportationRepositories ```cs -public async Task> SearchTransportationsAsync( - short? vehicleTypeId, - int? fromCityId, int? toCityId, - DateTime? startDate, DateTime? endDate) -{ - var query = DbContext.Transportations - .Include(x => x.Vehicle) +public class TransportationRepository : + BaseRepository, + ITransportationRepository + { + public TransportationRepository(ApplicationDBContext dbContext) : base(dbContext) + { + + } + + public async Task> SearchTransportationsAsync( + short? vehicleTypeId, + int? fromCityId, + int? toCityId, + DateTime? startDate, + DateTime? endDate) + { + var query = DbContext.Transportations + .Include(x => x.Vehicle) .Include(x => x.FromLocation).ThenInclude(x => x.City) .Include(x => x.ToLocation).ThenInclude(x => x.City) .Include(x => x.Company) .AsQueryable(); - query = query.Where(x => vehicleTypeId == null || x.Vehicle.VehicleTypeId == vehicleTypeId.Value); - - query = query.Where - (x => fromCityId == null || x.FromLocation.CityId == fromCityId.Value); - - query = query.Where - (x => toCityId == null || x.ToLocation.CityId == toCityId.Value); - - query = query.Where - (x => startDate == null || x.StartDateTime.Date == startDate.Value.Date); - - query = query.Where - (x => endDate == null || - (x.EndDateTime.HasValue && x.EndDateTime.Value == endDate.Value.Date)); + query = query.Where(x => vehicleTypeId == null || x.Vehicle.VehicleTypeId == vehicleTypeId.Value); + query = query.Where(x => fromCityId == null || x.FromLocation.CityId == fromCityId.Value); + query = query.Where(x => toCityId == null || x.ToLocation.CityId == toCityId.Value); + query = query.Where(x => startDate == null || x.StartDateTime.Date == startDate.Value.Date); + query = query.Where(x => endDate == null || (x.EndDateTime.HasValue && x.EndDateTime.Value == endDate.Value.Date)); - return await query.ToListAsync(); -} + return await query.ToListAsync(); + } + } ```