Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created July 7, 2020 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/997c6cf97e841787125983ec99fa2073 to your computer and use it in GitHub Desktop.
Save gavilanch/997c6cf97e841787125983ec99fa2073 to your computer and use it in GitHub Desktop.
[HttpGet("{id}")]
public async Task<ActionResult<Person>> Get(int id)
{
var person = await context.People.Include(x => x.MoviesActors).ThenInclude(x => x.Movie).FirstOrDefaultAsync(x => x.Id == id);
if (person == null) { return NotFound(); }
return person;
}
@CMcLean48
Copy link

Hi Felipe,
i'm still stuck. (my entity frameworks knowledge is lacking).. this is my individualperson.razor. -- i can render the name,dob, picture, and bio ok. It says no records to show, but there should be one.
Is this close at all?

@Person.Name

@Person.DateOfBirth.Value.ToString("MMMM dd yyyy")

@foreach (var item in MoviesActors) { }
Actors Movies
@item.Movie

}

@code {
[Parameter] public int PersonId { get; set; }
Person Person;

private List<MoviesActors> MoviesActors = new List<MoviesActors>()
protected async override Task OnInitializedAsync()
{
    Person = await personRepository.GetPersonById(PersonId);
}

}

@CMcLean48
Copy link

oops..sorry markup didn't work too well. I got it working using a generic list, and foreach (var item in Person.MoviesActors). Now to try to render using movielist component.. it looks so much better :-). Thanks for the controller code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment