public DataResultHero GetHeroes(string name, string heroName, string sort, string dir = "asc")
        {
            IQueryable <Hero> query = context.Heroes;

            if (!string.IsNullOrWhiteSpace(name))
            {
                query = query.Where(h => h.Name == name);
            }
            if (!string.IsNullOrWhiteSpace(heroName))
            {
                query = query.Where(h => h.HeroName == heroName);
            }
            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;

                case "HeroName":
                    if (dir == "asc")
                    {
                        query = query.OrderBy(h => h.HeroName);
                    }
                    else if (dir == "desc")
                    {
                        query = query.OrderByDescending(h => h.HeroName);
                    }
                    break;
                }
            }
            var result = new DataResultHero()
            {
                Data = query.Include(h => h.FeaturedMovies).ToList()
            };

            return(result);
        }
Example #2
0
        public IActionResult GetHeroFromMovie(int id)
        {
            var movie = context.MarvelMovies
                        .Include(d => d.Hero)
                        .SingleOrDefault(d => d.Id == id);

            if (movie == null)
            {
                return(NotFound());
            }

            var result = new DataResultHero()
            {
                Data = new List <Hero>()
                {
                    movie.Hero
                }
            };

            return(Ok(result));
        }