[f5f7c24] | 1 | using Dal.ApplicationStorage.DataAccess.Abstract;
|
---|
| 2 | using Microsoft.AspNetCore.Mvc;
|
---|
| 3 | using Models.DataTransferObjects.Serach;
|
---|
| 4 | using Models.JSON;
|
---|
| 5 | using Models.ViewModels;
|
---|
| 6 |
|
---|
| 7 | namespace ocrent.Controllers
|
---|
| 8 | {
|
---|
| 9 | public class SearchController : Controller
|
---|
| 10 | {
|
---|
| 11 | private readonly ISearchDa _searchDa;
|
---|
| 12 | public SearchController(ISearchDa searchDa)
|
---|
| 13 | {
|
---|
| 14 | _searchDa = searchDa;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | public async Task<IActionResult> Index()
|
---|
| 18 | {
|
---|
| 19 | var locations = await _searchDa.GetLocations();
|
---|
| 20 | var brands = await _searchDa.GetVehicleBrands();
|
---|
| 21 |
|
---|
| 22 | var viewModel = new SearchViewModel();
|
---|
| 23 | viewModel.Brands = brands;
|
---|
| 24 | viewModel.Locations = locations;
|
---|
| 25 |
|
---|
| 26 | return View(viewModel);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | [HttpPost]
|
---|
| 30 | public async Task<IActionResult> SearchData(SearchJSON data)
|
---|
| 31 | {
|
---|
| 32 | var model = await _searchDa.GetVehiclesBySearchParameters(data);
|
---|
| 33 |
|
---|
| 34 | return Json(Url.Action("Result", "Search", new {city = data.City, brand = data.Brand, startDate = data.StartDate, endDate = data.EndDate}));
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public async Task<IActionResult> Result(string city, string brand, string startDate, string endDate)
|
---|
| 38 | {
|
---|
| 39 | var data = new SearchJSON()
|
---|
| 40 | {
|
---|
| 41 | City = city,
|
---|
| 42 | Brand = brand,
|
---|
| 43 | StartDate = startDate,
|
---|
| 44 | EndDate = endDate
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | List<CarsDTO> model = new List<CarsDTO>();
|
---|
| 48 | if(city!= null && brand != null)
|
---|
| 49 | {
|
---|
| 50 | model = await _searchDa.GetVehiclesBySearchParameters(data);
|
---|
| 51 | }
|
---|
| 52 | else if(brand == null && city != null)
|
---|
| 53 | {
|
---|
| 54 | model = await _searchDa.GetVehilcesByLocation(data);
|
---|
| 55 | }
|
---|
| 56 | else if(brand != null && city == null)
|
---|
| 57 | {
|
---|
| 58 | model = await _searchDa.GetVehiclesByBrand(data);
|
---|
| 59 | }
|
---|
| 60 | else
|
---|
| 61 | {
|
---|
| 62 | model = await _searchDa.GetAllVehicles();
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | return View(model);
|
---|
| 67 |
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|