public async Task <IActionResult> GetEsrb([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var esrb = await _context.Esrb.Include(es => es.VideoGames).FirstAsync(es => es.Esrbid == id); if (esrb == null) { return(NotFound()); } ESRBDTO esdto = new ESRBDTO() { ESRBID = esrb.Esrbid, Rating = esrb.Rating, VideoGames = new List <VideoGamesDTO>() }; foreach (VideoGames vg in esrb.VideoGames) { VideoGamesDTO vgdto = new VideoGamesDTO() { VideoGamesID = vg.Id, Title = vg.Title, System = vg.System, ReleaseDate = vg.ReleaseDate, ESRB = vg.Esrb, Publisher = vg.Publisher, Developer = vg.Developer }; esdto.VideoGames.Add(vgdto); } return(Ok(esdto)); }
public IEnumerable <ESRBDTO> GetEsrb() { List <Esrb> esrb = _context.Esrb.Include(es => es.VideoGames).ToList(); List <ESRBDTO> esrbDTOList = new List <ESRBDTO>(); foreach (Esrb es in esrb) { List <VideoGamesDTO> videogamesDTOList = new List <VideoGamesDTO>(); foreach (VideoGames vg in es.VideoGames) { VideoGamesDTO vgDTO = new VideoGamesDTO() { VideoGamesID = vg.Id, Title = vg.Title, System = vg.System, ReleaseDate = vg.ReleaseDate, ESRB = vg.Esrb, Publisher = vg.Publisher, Developer = vg.Developer }; videogamesDTOList.Add(vgDTO); } ESRBDTO esdto = new ESRBDTO() { ESRBID = es.Esrbid, Rating = es.Rating }; esrbDTOList.Add(esdto); } return(esrbDTOList); }