Beispiel #1
0
        /// <summary>
        /// Limited to the top 5 comics ordered by Name Ascending
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public static List <Comic> GetComics(Character character)
        {
            var creds  = new Credentials();
            var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey);

            var filter = new ComicRequestFilter();

            filter.OrderBy(OrderResult.NameAscending);
            filter.Limit = 5;

            var comicResponse = client.FindCharacterComics(character.Id.ToString(), filter);

            return(ResultsToList(comicResponse));
        }
Beispiel #2
0
        /// <summary>
        /// Limited to the 1 comic ordered by Name Ascending
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public static Comic GetComic(string title)
        {
            var creds  = new Credentials();
            var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey);

            var filter = new ComicRequestFilter();

            filter.OrderBy(OrderResult.NameAscending);
            filter.Limit           = 1;
            filter.TitleStartsWith = title;

            var comicResponse = client.FindComics(filter);

            return(ResultsToList(comicResponse)[0]);
        }
Beispiel #3
0
        public JsonResult SomeActionMethod(NameViewModel postdata)
        {
            const string apiKey     = "YOUR API PUBLIC KEY";
            const string privateKey = "YOUR API PRIVATE KEY";

            var client = new MarvelRestClient(apiKey, privateKey);
            List <ResultViewModel> results = null;

            if (postdata.Type.ToLower() == "character")
            {
                var filter = new CharacterRequestFilter {
                    NameStartsWith = postdata.Name
                };
                filter.OrderBy(OrderResult.NameAscending);
                filter.Limit = 40;

                var response = client.GetCharacters(filter);

                if (response.Code == "200")
                {
                    results =
                        response.Data.Results.Select(res =>
                                                     new ResultViewModel {
                        Id = res.Id, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
                    }).ToList();
                }
            }
            else
            {
                var filter = new ComicRequestFilter {
                    TitleStartsWith = postdata.Name
                };
                filter.OrderBy(OrderResult.NameAscending);
                filter.Limit = 40;

                var response = client.GetComics(filter);

                if (response.Code == "200")
                {
                    results =
                        response.Data.Results.Select(res =>
                                                     new ResultViewModel {
                        Id = res.Id, Name = res.Title, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
                    }).ToList();
                }
            }
            return(Json(results));
        }