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()); } }
public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filterDto) { using (NorthwindContext context = new NorthwindContext()) { var filterExpression = GetFilterExpression(filterDto); 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 join carImage in context.CarImages on car.CarId equals carImage.CarId select new CarDetailDto { CarId = car.CarId, BrandId = brand.BrandId, ColorId = color.ColorId, Images = (from i in context.CarImages where i.CarId == car.CarId select i.ImagePath).ToList(), ModelYear = car.ModelYear, BrandName = brand.BrandName, Description = car.Description, ColorName = color.ColorName, DailyPrice = car.DailyPrice }; return(result.ToList()); // tolist yapmadan query'e dönüştürüp verileri çekmez. } }
public IActionResult GetCarsDetails([FromQuery] CarDetailFilterDto filterDto) { var result = _carService.GetCarsFiltreDetails(filterDto); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult GetCarsDetails([FromQuery] CarDetailFilterDto filterDto) { var test = HttpContext.Request.Query["brandid"]; var result = _carService.GetCarsDetails(filterDto); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IDataResult <List <CarDetailDto> > GetCarDetailsByFilter(CarDetailFilterDto carDetailFilterDto) { foreach (PropertyInfo prop in carDetailFilterDto.GetType().GetProperties()) { if ((int)prop.GetValue(carDetailFilterDto) == 0) { prop.SetValue(carDetailFilterDto, null); } } Expression <Func <CarDetailDto, bool> > filter = Filter.DynamicFilter <CarDetailDto, CarDetailFilterDto>(carDetailFilterDto); return(new SuccessDataResult <List <CarDetailDto> >(_carDal.GetCarDetails(filter))); }
public IActionResult GetByFilter(int brandId, int colorId) { CarDetailFilterDto carDetailFilterDto = new CarDetailFilterDto { BrandId = brandId, ColorId = colorId }; var result = _carService.GetCarDetailsByFilter(carDetailFilterDto); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IDataResult <List <CarDTO> > GetCarDetailsFilter(CarDetailFilterDto filterDto) { foreach (PropertyInfo property in filterDto.GetType().GetProperties()) { if ((int)property.GetValue(filterDto) == 0) { property.SetValue(filterDto, null); } } Func <CarDTO, bool> filter = FilterHelper.DynamicFilter <CarDTO, CarDetailFilterDto>(filterDto); return(GetCarDetails(filter)); }
public IActionResult GetCarDetailsFilter(int brandid, int colorid) { CarDetailFilterDto filterDto = new CarDetailFilterDto { BrandId = brandid, ColorId = colorid, }; var result = _service.GetCarDetailsFilter(filterDto); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filterDto) { using (ReCapContext context = new ReCapContext()) { var result = from c in context.Car join b in context.Brand on c.BrandId equals b.Id join col in context.Color on c.ColorId equals col.Id select new CarDetailDto { Id = c.Id, BrandName = b.Name, Description = c.Description, DailyPrice = c.DailyPrice, ColorName = col.Name }; return(result.ToList()); } }
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()); } }
public IDataResult <List <CarDetailDto> > GetCarsDetails(CarDetailFilterDto filterDto) { //Expression propertyExp,someValue,containsMethodExp,combinedExp; //Expression<Func<Car, bool>> exp = c => true, oldExp; //MethodInfo method; //var parameterExp = Expression.Parameter(typeof(Car), "type"); //foreach (PropertyInfo propertyInfo in filterDto.GetType().GetProperties()) //{ // if (propertyInfo.GetValue(filterDto,null) != null) // { // oldExp = exp; // propertyExp = Expression.Property(parameterExp, propertyInfo.Name); // method = typeof(int).GetMethod("Equals", new[] { typeof(int) }); // someValue = Expression.Constant(filterDto.GetType().GetProperty(propertyInfo.Name).GetValue(filterDto, null), typeof(int)); // containsMethodExp = Expression.Call(propertyExp, method, someValue); // exp = Expression.Lambda<Func<Car, bool>>(containsMethodExp, parameterExp); // combinedExp = Expression.AndAlso(exp.Body,oldExp.Body); // exp = Expression.Lambda<Func<Car, bool>>(combinedExp, exp.Parameters[0]); // } //} return(new SuccessDataResult <List <CarDetailDto> >(_iCarDal.GetAllCarDetailsByFilter(filterDto))); }
public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filterDto) { using (MyDbContext context = new MyDbContext()) { var filterExpression = GetFilterExpression(filterDto); 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 { Id = car.Id, CarName = car.CarName, BrandName = brand.BrandName, ColorName = color.ColorName, ModelYear = car.ModelYear, DailyPrice = car.DailyPrice, ImagePath = context.CarImages.Where(x => x.CarId == car.Id).FirstOrDefault().ImagePath, Descriptions = car.Descriptions, MinFindeksScore = car.MinFindeksScore, Status = !(context.Rentals.Any(r => r.CarId == car.Id && r.ReturnDate == null)) }; return(result.ToList()); } }
public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filterDto) { using (CarContext context = new CarContext()) { var filterExpression = GetFilterExpression(filterDto); 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, ModelYear = car.ModelYear, Status = !(context.Rentals.Any(r => r.CarId == car.CarId && (r.ReturnDate == null || r.ReturnDate > DateTime.Now))), ImagePath = (from carImage in context.CarImages where carImage.CarId == car.CarId select carImage.ImagePath).FirstOrDefault(), MinFindex = car.MinFindex }; return(result.ToList()); //tolist yapmadan query'e dönüştürüp verileri çekmez. } }
public IDataResult <List <CarDetailDto> > GetCarsDetailsByFilter(CarDetailFilterDto filterDto) { return(new SuccessDataResult <List <CarDetailDto> >(_carDal.GetAllCarDetailsByFilter(filterDto))); }
public List <CarDetailDto> GetAllCarDetailsByFilter(CarDetailFilterDto filter) { throw new NotImplementedException(); }