public IActionResult Details(int id) { var pastry = _pastryRepository.GetPastryById(id); if (pastry == null) { return(NotFound()); } return(View(pastry)); }
//View that we can acces when we click on a pastry public IActionResult Details(int id) { //ViewModel that we use in order to show Pastry with Comments PastryDetailViewModel viewmodelfordetails = new PastryDetailViewModel(); //In the PastryDetailViewModel we have All the Pasteries with properties and All the Comments in a List viewmodelfordetails.Comments = new List <Comment>(); //In order to show the comments we need to know which Product where are showing comments for and setting the ViewModel for that Pastry Pastry pastry = repositoryofpastries.GetPastryById(id); viewmodelfordetails.PastryDetails = pastry; //Now we can access the Comments for that specific Pastry so we create a list that we are going to pass on to the ViewModel IEnumerable <Comment> ListOfComments; //Gets the Comments by the Pastry ID ListOfComments = repositoryofcomments.GetCommentByPastryId(id); //And passes on to the ViewModel List viewmodelfordetails.Comments = ListOfComments.ToList(); //Returns a View Model for View Detail return(View(viewmodelfordetails)); }