public DataResultVillain GetVillains(string name, string sort, string dir = "asc") { IQueryable <Villain> query = context.Villains; if (!string.IsNullOrWhiteSpace(name)) { query = query.Where(h => h.Name == name); } if (!string.IsNullOrWhiteSpace(sort)) { switch (sort) { case "Name": if (dir == "asc") { query = query.OrderBy(h => h.Name); } else if (dir == "desc") { query = query.OrderByDescending(h => h.Name); } break; case "Actor": if (dir == "asc") { query = query.OrderBy(h => h.Actor); } else if (dir == "desc") { query = query.OrderByDescending(h => h.Actor); } break; } } var result = new DataResultVillain() { Data = query.Include(v => v.FeaturedMovies).ToList() }; return(result); }
public IActionResult GetVillainFromMovie(int id) { var movie = context.MarvelMovies .Include(d => d.Villain) .SingleOrDefault(d => d.Id == id); if (movie == null) { return(NotFound()); } var result = new DataResultVillain() { Data = new List <Villain>() { movie.Villain } }; return(Ok(result)); }