public IActionResult AllSold(int page = 1) { try { var cars = this.car.AllSold(page); var totalCars = this.car.TotalSold(); var maxPage = Math.Ceiling((double)totalCars / 20); var model = new AllCarsViewModel { Cars = cars, Total = totalCars, CurrentPage = page }; if (page > maxPage) { throw new Exception("Max Page is exceeded"); } return(View(model)); } catch (Exception ex) { LogExceptionWithMessage(ex); var model = new AllCarsViewModel() { CurrentPage = 1, Total = 1 }; return(View(model)); } }
public async Task <IActionResult> MyCars() { var user = await this.userManager.GetUserAsync(this.User); var cars = this.carService.GetAllByUserId(user.Id); var list = new List <AllCarsViewModel>(); foreach (var car in cars) { var currentCar = new AllCarsViewModel { Id = car.Id, Make = this.makeService.GetNameById(car.MakeId), Model = this.modelService.GetNameById(car.ModelId), RegistrationNumber = car.RegistrationNumber, CarImage = this.carImageService.GetImageUrlByCarId(car.Id), }; list.Add(currentCar); } return(this.View(list)); }