public async Task <IActionResult> All(int id = 1) { var page = id; var cars = await this.carsService.GetAllWithPagingAsync <CarsServiceAllModel>(GlobalConstants.ItemsPerPageAdmin, (page - 1) *GlobalConstants.ItemsPerPageAdmin); var carsWithAddress = await this.carsService.GetAllAsync <CarsServiceAllModel>(); var viewModel = new CarsAllViewModelCollection(); foreach (var car in cars) { car.Rating = carsWithAddress.Where(c => c.Id == car.Id) .Select(d => d.Rating) .FirstOrDefault(); viewModel.Cars.Add(car.To <CarsAllViewModel>()); } var count = await this.carsService.GetCountAsync(); viewModel.PagesCount = (int)Math.Ceiling((double)count / GlobalConstants.ItemsPerPageAdmin); if (viewModel.PagesCount == 0) { viewModel.PagesCount = 1; } viewModel.CurrentPage = page; return(this.View(viewModel)); }
public async Task <IActionResult> ByParking(int id) { var cars = await this.carsService.GetAllByParkingAsync <CarsServiceAllModel>(id); var viewModel = new CarsAllViewModelCollection() { Cars = cars.Select(c => c.To <CarsAllViewModel>()).ToList(), }; return(this.View(viewModel)); }
public async Task <IActionResult> All(string currentFilter, string searchString, int id = 1) { var page = id; var cars = await this.carsService.GetAllWithPagingAsync <CarsServiceAllModel>(GlobalConstants.ItemsPerPage, (page - 1) *GlobalConstants.ItemsPerPage); var countries = await this.countriesService.GetAllAsync <CountriesServiceDropDownModel>(); var towns = await this.townsService.GetAllAsync <TownsServiceDropDownModel>(); var parkings = await this.parkingsService.GetAllAsync <ParkingsServiceDropDownModel>(); var count = await this.carsService.GetCountAsync(); var viewModel = new CarsAllViewModelCollection(); viewModel.Countries = countries.Select(c => c.Name).ToList(); viewModel.Towns = towns.Select(t => t.Name).ToList(); viewModel.Parkings = parkings.Select(p => p.Name).ToList(); if (!string.IsNullOrEmpty(searchString) && viewModel.Countries.Contains(searchString)) { if (searchString != (string)this.TempData["SearchString"]) { id = 1; this.TempData["SearchString"] = searchString; } page = id; cars = await this.carsService.GetAllByCountryWithPagingAsync <CarsServiceAllModel> (searchString, GlobalConstants.ItemsPerPage, (page - 1) *GlobalConstants.ItemsPerPage); count = await this.carsService.GetCountByCountryAsync(searchString); } else if (!string.IsNullOrEmpty(searchString) && viewModel.Towns.Contains(searchString)) { if (searchString != (string)this.TempData["SearchString"]) { id = 1; this.TempData["SearchString"] = searchString; } page = id; cars = await this.carsService.GetAllByTownWithPagingAsync <CarsServiceAllModel> (searchString, GlobalConstants.ItemsPerPage, (page - 1) *GlobalConstants.ItemsPerPage); count = await this.carsService.GetCountByTownAsync(searchString); } else if (!string.IsNullOrEmpty(searchString) && viewModel.Parkings.Contains(searchString)) { if (searchString != (string)this.TempData["SearchString"]) { id = 1; this.TempData["SearchString"] = searchString; } page = id; cars = await this.carsService.GetAllByParkingWithPagingAsync <CarsServiceAllModel> (searchString, GlobalConstants.ItemsPerPage, (page - 1) *GlobalConstants.ItemsPerPage); count = await this.carsService.GetCountByParkingAsync(searchString); } else { searchString = currentFilter; } this.ViewData["CurrentFilter"] = searchString; this.TempData["SearchString"] = searchString; viewModel.Cars = cars.Select(c => c.To <CarsAllViewModel>()).ToList(); viewModel.PagesCount = (int)Math.Ceiling((double)count / GlobalConstants.ItemsPerPage); if (viewModel.PagesCount == 0) { viewModel.PagesCount = 1; } viewModel.CurrentPage = page; return(this.View(viewModel)); }