source: Application/ocrent/Controllers/SearchController.cs

Last change on this file was f5f7c24, checked in by 192011 <mk.snicker@…>, 17 months ago

Initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1using Dal.ApplicationStorage.DataAccess.Abstract;
2using Microsoft.AspNetCore.Mvc;
3using Models.DataTransferObjects.Serach;
4using Models.JSON;
5using Models.ViewModels;
6
7namespace 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}
Note: See TracBrowser for help on using the repository browser.