Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -74,11 +74,22 @@ public interface ITransportationRepository : IRepository<Transportation, long>
|
||||
📂 Suggested Folder: Infrastructure/Services/Services/TransportationRepositories
|
||||
|
||||
```cs
|
||||
public async Task<IEnumerable<Transportation>> SearchTransportationsAsync(
|
||||
public class TransportationRepository :
|
||||
BaseRepository<ApplicationDBContext, Transportation, long>,
|
||||
ITransportationRepository
|
||||
{
|
||||
public TransportationRepository(ApplicationDBContext dbContext) : base(dbContext)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Transportation>> SearchTransportationsAsync(
|
||||
short? vehicleTypeId,
|
||||
int? fromCityId, int? toCityId,
|
||||
DateTime? startDate, DateTime? endDate)
|
||||
{
|
||||
int? fromCityId,
|
||||
int? toCityId,
|
||||
DateTime? startDate,
|
||||
DateTime? endDate)
|
||||
{
|
||||
var query = DbContext.Transportations
|
||||
.Include(x => x.Vehicle)
|
||||
.Include(x => x.FromLocation).ThenInclude(x => x.City)
|
||||
@@ -86,22 +97,14 @@ public async Task<IEnumerable<Transportation>> SearchTransportationsAsync(
|
||||
.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 => 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user