add unsaled cars filtration

This commit is contained in:
Zakharov_Rostislav 2024-05-13 15:26:31 +04:00
parent 3766e03974
commit f4dd73833d
3 changed files with 10 additions and 4 deletions

View File

@ -9,5 +9,6 @@ namespace CarShowroomDataModels.SearchModel
public class CarSearch public class CarSearch
{ {
public int? Id; public int? Id;
public bool? IsSaled;
} }
} }

View File

@ -34,7 +34,9 @@ namespace CarShowroomDatabaseStorage.Storages
return context.Cars return context.Cars
.Include(c => c.Model) .Include(c => c.Model)
.ThenInclude(m => m.Make) .ThenInclude(m => m.Make)
.Where(x => !model.Id.HasValue || x.Id == model.Id) .Where(x =>
!model.Id.HasValue || x.Id == model.Id &&
(!model.IsSaled.HasValue || x.IsSaled == model.IsSaled))
.Select(x => x.GetView()) .Select(x => x.GetView())
.ToList(); .ToList();
} }

View File

@ -24,16 +24,19 @@ namespace CarShowroomRestApi.Controllers
{ {
try try
{ {
return _logic.ReadList(null); return _logic.ReadList(new CarSearch
{
IsSaled = false,
});
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка получения списка машин"); _logger.LogError(ex, "Ошибка получения списка машин");
throw; throw;
} }
} }
[HttpGet] [HttpGet]
public CarView? GetCar(int CarId) public CarView? GetCar(int CarId)
{ {
try try