// GET: Reviews public ActionResult Index() { //list of film reviews model object to link //reviews with related films List <FilmReviewViewModel> FilmReviewList = new List <FilmReviewViewModel>(); //list of review objects to cycle through and map ids List <Review> Reviews; //populate the list with the review records from the database Reviews = db.Reviews.ToList(); //loop through each review in the list of data (each row) foreach (Review r in Reviews) { //select the film record where the ids match Film film = db.Films.Where(x => x.FilmID == r.FilmID).Single(); //create a new film review view model object to add FilmReviewViewModel toAdd = new FilmReviewViewModel(); //set the review record and film record from the //ones matched in the loop toAdd.Review = r; toAdd.Film = film; //add to the list of film review objects FilmReviewList.Add(toAdd); } //send the list of view model objects to the View return(View(FilmReviewList)); }
// GET: Reviews/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Review review = db.Reviews.Find(id); if (review == null) { return(HttpNotFound()); } //find the related film Film film = db.Films.Where(x => x.FilmID == review.FilmID).Single(); //create a new view model object and assign the review and film details FilmReviewViewModel FilmReview = new FilmReviewViewModel(); FilmReview.Review = review; FilmReview.Film = film; //send the view model to the view return(View(FilmReview)); }