// GET: Cars public ActionResult Cars() { AdvertRepository advertRepository = new AdvertRepository(); CarsRepository carsRepository = new CarsRepository(); CarPhotoRepository carPhotoRepository = new CarPhotoRepository(); List <AdvertViewModel> advertViews = new List <AdvertViewModel>(); var result = carsRepository.GetAll(); var resultadvert = advertRepository.GetAll(); foreach (var item in result) { advertViews.Add(new AdvertViewModel { Carss = item, Photo = carPhotoRepository.GetByFilterx(x => x.CarId == item.Id).Photo }); } foreach (var item in resultadvert) { advertViews.ForEach(x => x.Adverts = item); } return(View(advertViews)); }
// GET: Advert public ActionResult Index() { IEnumerable <Advert> adverts = advRepository.GetAll(); return(View(adverts)); }