Пример #1
0
 public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filterDto)
 {
     using (RentCarContext context = new RentCarContext())
     {
         var filterExpression = filterDto.GetFilterExpression <Car>();
         var result           = from cr in filterExpression == null ? context.Cars : context.Cars.Where(filterExpression)
                                join cl in context.Colors on cr.ColorId equals cl.Id
                                join b in context.Brands on cr.BrandId equals b.Id
                                select new CarDetailDto
         {
             Id              = cr.Id,
             ModelYear       = cr.ModelYear,
             Description     = cr.Description,
             BrandName       = b.BrandName,
             ColorName       = cl.ColorName,
             DailyPrice      = cr.DailyPrice,
             ABS             = cr.ABS,
             Fuel            = cr.Fuel,
             Gear            = cr.Gear,
             ParkingSensor   = cr.ParkingSensor,
             MinFindeksScore = cr.MinFindeksScore,
             Status          = !context.Rentals.Any(r => r.CarId == cr.Id && (r.ReturnDate == null || r.ReturnDate > DateTime.Now))
         };
         return(result.ToList());
     }
 }
Пример #2
0
 public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filterDto)
 {
     using (NorthwindContext context = new NorthwindContext())
     {
         var filterExpression = filterDto.GetFilterExpression <Car>();
         var result           = from car in filterExpression == null ? context.Cars : context.Cars.Where(filterExpression)
                                join color in context.Colors on car.ColorId equals color.ColorId
                                join brand in context.Brands on car.BrandId equals brand.BrandId
                                select new CarDetailDto
         {
             CarId       = car.CarId,
             BrandName   = brand.BrandName,
             CarName     = car.CarName,
             Description = car.Description,
             ColorName   = color.ColorName,
             DailyPrice  = car.DailyPrice
         };
         return(result.ToList()); // tolist yapmadan query'e dönüştürüp verileri çekmez.
     }
 }
Пример #3
0
 public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filterDto)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var filterExpression = filterDto.GetFilterExpression <Car>();
         var result           = from car in filterExpression == null ? context.Cars : context.Cars.Where(filterExpression)
                                join color in context.Colors on car.ColorId equals color.Id
                                join brand in context.Brands on car.BrandId equals brand.Id
                                select new CarDetailDto
         {
             CarId       = car.Id,
             BrandName   = brand.Name,
             CarName     = car.CarName,
             Description = car.Description,
             ColorName   = color.Name,
             DailyPrice  = car.DailyPrice,
             ModelYear   = car.ModelYear
         };
         return(result.ToList());
     }
 }