public async Task <IActionResult> All(int id = 1) { var page = id; var drivers = await this.driversService.GetAllWithPagingAsync <DriversServiceAllModel>(GlobalConstants.ItemsPerPageAdmin, (page - 1) *GlobalConstants.ItemsPerPageAdmin); var driversWithRatings = await this.driversService.GetAllAsync <DriversServiceAllModel>(); var viewModel = new DriversAllViewModelCollection(); foreach (var driver in drivers) { driver.Rating = driversWithRatings.Where(d => d.Id == driver.Id) .Select(d => d.Rating) .FirstOrDefault(); viewModel.Drivers.Add(driver.To <DriversAllViewModel>()); } var count = await this.driversService.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> All(int id = 1) { var page = id; var drivers = await this.driversService.GetAllWithPagingAsync <DriversServiceAllModel>(GlobalConstants.ItemsPerPage, (page - 1) *GlobalConstants.ItemsPerPage); var viewModel = new DriversAllViewModelCollection(); viewModel.Drivers = drivers.Select(d => d.To <DriversAllViewModel>()).ToList(); var count = await this.driversService.GetCountAsync(); viewModel.PagesCount = (int)Math.Ceiling((double)count / GlobalConstants.ItemsPerPage); if (viewModel.PagesCount == 0) { viewModel.PagesCount = 1; } viewModel.CurrentPage = page; return(this.View(viewModel)); }