Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -74,34 +74,37 @@ public interface ITransportationRepository : IRepository<Transportation, long>
|
|||||||
📂 Suggested Folder: Infrastructure/Services/Services/TransportationRepositories
|
📂 Suggested Folder: Infrastructure/Services/Services/TransportationRepositories
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
public async Task<IEnumerable<Transportation>> SearchTransportationsAsync(
|
public class TransportationRepository :
|
||||||
short? vehicleTypeId,
|
BaseRepository<ApplicationDBContext, Transportation, long>,
|
||||||
int? fromCityId, int? toCityId,
|
ITransportationRepository
|
||||||
DateTime? startDate, DateTime? endDate)
|
{
|
||||||
{
|
public TransportationRepository(ApplicationDBContext dbContext) : base(dbContext)
|
||||||
var query = DbContext.Transportations
|
{
|
||||||
.Include(x => x.Vehicle)
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Transportation>> 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.FromLocation).ThenInclude(x => x.City)
|
||||||
.Include(x => x.ToLocation).ThenInclude(x => x.City)
|
.Include(x => x.ToLocation).ThenInclude(x => x.City)
|
||||||
.Include(x => x.Company)
|
.Include(x => x.Company)
|
||||||
.AsQueryable();
|
.AsQueryable();
|
||||||
query = query.Where(x => vehicleTypeId == null || x.Vehicle.VehicleTypeId == vehicleTypeId.Value);
|
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
|
return await query.ToListAsync();
|
||||||
(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