private static List <Personagem> BaixarPersonagens(MarvelRestClient client)
        {
            int offset      = 0;
            int limit       = 100;
            int total       = int.MaxValue;
            var personagens = new List <Personagem>();

            while (offset < total)
            {
                var filtro = new CharacterRequestFilter()
                {
                    Limit  = limit,
                    Offset = offset
                };

                var response = client.FindCharacters(filtro);

                total   = Convert.ToInt32(response.Data.Total);
                offset += limit;

                foreach (var character in response.Data.Results)
                {
                    var personagem = new Personagem()
                    {
                        IdPersonagem    = character.Id,
                        Nome            = character.Name,
                        QuantQuadrinhos = character.Comics.Items.Count
                    };

                    personagens.Add(personagem);
                }
            }

            return(personagens);
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";
            System.Diagnostics.Trace.WriteLine("In Home Controller");

            // accessing developer.marvel.com

            //HTTP GET
            // http://gateway.marvel.com/v1/public/comics?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150


            // randomize which of the 50 retrieved characters will be displayed
            int characterIndex = new Random().Next(0, 99);


            var marvelClient = new MarvelRestClient(pb_key, pr_key);
            var filter       = new CharacterRequestFilter
            {
                Limit = 100
            };

            var response = marvelClient.FindCharacters(filter);
            var imageUrl = response.Data.Results[characterIndex].Thumbnail.Path + "." +
                           response.Data.Results[characterIndex].Thumbnail.Extension;

            if (imageUrl.Contains("image_not_available"))
            {
                imageUrl = "https://www.writeups.org/wp-content/uploads/Spider-Man-Marvel-Comics-Peter-Parker-Profile.jpg";
            }
            ViewBag.imageUrl = imageUrl;


            return(View());
        }
        public async Task <DefaultResult <List <CharacterResponse> > > GetAsync(CharacterRequestFilter filters)
        {
            var defaultResult = new DefaultResult <List <CharacterResponse> >();
            var baseFilter    = filters.GetFilterDefinition();

            defaultResult.SetData((await _characterRepository.GetAsync(baseFilter)).Select(x => (CharacterResponse)x).ToList());
            return(defaultResult);
        }
Esempio n. 4
0
        /// <summary>
        /// Fetches lists of comic characters with optional filters.
        /// </summary>
        /// <param name="filter">
        /// Search query filter data
        /// </param>
        public virtual CharacterResult GetCharacters(CharacterRequestFilter filter = default(CharacterRequestFilter))
        {
            var request = new RestRequest(CharactersUrlSegment, Method.GET);

            // Parse filter
            //
            ParseCharacterFilter(request, filter);

            return(Execute <CharacterResult>(request));
        }
Esempio n. 5
0
        public static List <Character> FindByName(string name)
        {
            var creds  = new Credentials();
            var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey);

            var filter = new CharacterRequestFilter();

            filter.NameStartsWith = name;

            var response = client.FindCharacters(filter);

            return(ResultsToList(response));
        }
Esempio n. 6
0
        /// <summary>
        /// Fetches lists of characters which appear in a specific comic with optional filters.
        /// </summary>
        /// <param name="comicId">
        /// Comic unique identifier
        /// </param>
        /// <param name="filter">
        /// Search query filter data
        /// </param>
        public virtual CharacterResult GetComicCharacters(string comicId, CharacterRequestFilter filter = default(CharacterRequestFilter))
        {
            // Build request url
            //
            string requestUrl =
                string.Format("{0}/{1}/characters", ComicsUrlSegment, comicId);

            var request = new RestRequest(requestUrl, Method.GET);

            // Parse filter
            //
            ParseCharacterFilter(request, filter);

            return(Execute <CharacterResult>(request));
        }
Esempio n. 7
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));
        }
Esempio n. 8
0
 private void ParseCharacterFilter(IRestRequest request, CharacterRequestFilter filter)
 {
     if (filter != null)
     {
         if (filter.Name.HasValue())
         {
             request.AddParameter("name", filter.Name);
         }
         if (filter.NameStartsWith.HasValue())
         {
             request.AddParameter("nameStartsWith", filter.NameStartsWith);
         }
         if (filter.ModifiedSince.HasValue)
         {
             request.AddParameter("modifiedSince", filter.ModifiedSince.Value.ToString("yyyy-MM-dd"));
         }
         if (filter.Comics.HasValue())
         {
             request.AddParameter("comics", filter.Comics);
         }
         if (filter.Series.HasValue())
         {
             request.AddParameter("series", filter.Series);
         }
         if (filter.Events.HasValue())
         {
             request.AddParameter("events", filter.Events);
         }
         if (filter.Stories.HasValue())
         {
             request.AddParameter("stories", filter.Stories);
         }
         if (filter.ResultSetOrder.HasValue())
         {
             request.AddParameter("orderBy", filter.ResultSetOrder);
         }
         if (filter.Limit.HasValue)
         {
             request.AddParameter("limit", filter.Limit.Value);
         }
         if (filter.Offset.HasValue)
         {
             request.AddParameter("offset", filter.Offset.Value);
         }
     }
 }
Esempio n. 9
0
        public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request)
        {
            // Initialize the marvel api client
            var client = new MarvelRestClient(PUBLICKEY, PRIVATEKEY);

            // Initialize an avengers team
            var team = new Types.AvengerTeam();

            // Initialize character request filter
            var characterRequestFilter = new CharacterRequestFilter();

            // Query marvel api for desired avengers
            // TODO: refine this logic to assemble stronger team
            characterRequestFilter.OrderBy(OrderResult.NameAscending);
            characterRequestFilter.Limit = 1;
            var characterResponse = client.FindCharacters(characterRequestFilter);

            foreach (var character in characterResponse.Data.Results)
            {
                // Initialize a comic listing filter to determine power for each avenger
                var comicRequestFilter = new ComicRequestFilter();
                comicRequestFilter.AddCharacter(character.Id);

                // Form avenger object
                var currentAvenger = new Types.Avenger();
                currentAvenger.name  = character.Name;
                currentAvenger.id    = character.Id;
                currentAvenger.power = client.FindCharacterComics(character.Id.ToString(), comicRequestFilter).Data.Total;

                // Add avenger to team
                team.AddAvengerToTeam(currentAvenger);
            }

            var message = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "AVENGERS", "DEFEND");

            await Methods.PostBattlefield(new Types.Item
            {
                Id    = message,
                Value = JsonConvert.SerializeObject(team.avengerTeam)
            });

            return(new FunctionResponse());
        }
        public async Task CharacterService_Get(CharacterRequestFilter filters)
        {
            #region LoadData
            var character1 = new Character(
                "id1",
                "name1",
                null,
                null,
                new House("id1", "name1", "mascot", "hof", "hog", "founder"),
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            var character2 = new Character(
                "id2",
                "name2",
                "role",
                "school",
                new House("id2", "name2", "mascot", "hof", "hog", "founder"),
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            var character3 = new Character(
                "id3",
                "name3",
                "role",
                "school",
                null,
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            var character4 = new Character(
                "id4",
                "name4",
                null,
                "school",
                null,
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            List <Character> characterList = new List <Character>()
            {
                character1, character2, character3, character4
            };

            var filterDefinition = filters.GetFilterDefinition();
            _characterRepositoryMock
            .Setup(x => x.GetAsync(filterDefinition, It.IsAny <System.Threading.CancellationToken>()))
            .Returns(Task.FromResult((IEnumerable <Character>)characterList));
            #endregion

            var getResult = await _characterService.GetAsync(filters);

            if (!string.IsNullOrEmpty(filters.Id))
            {
                characterList = characterList.Where(x => x.Id == filters.Id).ToList();
            }

            if (!string.IsNullOrEmpty(filters.Name))
            {
                characterList = characterList.Where(x => x.Name == filters.Name).ToList();
            }

            if (!string.IsNullOrEmpty(filters.Role))
            {
                characterList = characterList.Where(x => x.Role == filters.Role).ToList();
            }

            if (!string.IsNullOrEmpty(filters.School))
            {
                characterList = characterList.Where(x => x.School == filters.School).ToList();
            }

            if (!string.IsNullOrEmpty(filters.House))
            {
                characterList = characterList.Where(x => x.House != null && x.House.Id == filters.House).ToList();
            }

            if (!string.IsNullOrEmpty(filters.Patronus))
            {
                characterList = characterList.Where(x => x.Patronus == filters.Patronus).ToList();
            }

            Assert.True(getResult.Success);
            Assert.Equal(characterList.Count(), getResult.Data.Count());
        }
Esempio n. 11
0
        public async Task <ViewResult> /*RestResponse*//*RestRequest*//*CharacterResult*/ /*FindStoryCharacters(string storyId = "1009351", CharacterRequestFilter filter = null)*/ FindStoryCharacters(string storyId = "1009351", CharacterRequestFilter filter = null)
        {
            // Build request url
            //
            string requestUrl =
                string.Format("{0}/{1}/characters", StoriesUrlSegment, storyId);

            RestRequest request = new RestRequest(requestUrl, Method.GET);

            request.RequestFormat = DataFormat.Json;

            // Parse filter
            //
            //ParseCharacterFilter(request, filter);

            RestClient restClient = new RestClient("http://gateway.marvel.com/");

            //HttpRequest httpRequest = new HttpRequest()

            // GET api/values/getFromExternal
            //[HttpGet, Route("getFromExternal")]
            ////public async Task<IActionResult> GetFromExternal()
            ////{
            ////    using (var response = await HttpClient.GetAsync("https://*****:*****@"Content-Length", content.Length.ToString());

            //httpResponse.Headers.Add(  HttpHeader header = "Content-Type", Value = "application/json;charset=UTF-8" );

            //httpResponse.Headers.Add(Name = "Content-Type", Value = "application/json;charset=UTF-8");


            //ViewBag == httpResponse;


            ViewBag.Message = httpResponse;

            return(View(/*<Task>*//*httpResponse*/));

            //_ = response.Content;


            /*return*/ /*Execute*//*<CharacterResult>*//*(*//*(RestRequest)*//*Task*//*)*/;
        }
Esempio n. 12
0
        /*public virtual RestResponse*/

        public async Task <IActionResult> GetFromExternal(string storyId = "1009351", CharacterRequestFilter filter = null)
        {
            HttpClient httpClient = new HttpClient();

            using (var response = await httpClient.GetAsync("https://localhost:5001/api/externalEndpoint"))
            {
                string httprequestUrl =
                    string.Format("{0}/{1}/characters", StoriesUrlSegment, storyId);

                //HttpRequest httpRequest = new HttpRequest(httprequestUrl, Method.GET);



                HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, httprequestUrl);


                //request.RequestFormat = DataFormat.Json;

                HttpClient httpClient = new HttpClient/*("http://gateway.marvel.com/").BaseAddress*/ ();

                System.Uri uri = new System.Uri("http://gateway.marvel.com/");

                httpClient.BaseAddress = uri;

                var content = await response.Content.ReadAsAsync <IActionResult>();

                return(Ok(content));
            }

            //restClient.Execute(request);

            //restClient.DefaultParameters



            //            httpClient.DefaultRequestHeaders
            //.Accept
            //.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header

            //            request.AddHeader("Content-Type", "application/json;charset=UTF-8");

            //            if (!response.IsSuccessStatusCode)
            //                    return StatusCode((int)response.StatusCode);

            //                var responseContent = await response.Content.ReadAsStringAsync();
            //                var deserializedResponse = JsonConvert.DeserializeObject<List<string>>(responseContent);

            //                return Ok(deserializedResponse);
            //            }
            //        }
        }
Esempio n. 13
0
        public IActionResult Index(/*RestResponse restResponse*//*RestRequest request*//*NameViewModel postdata*/)
        {
            const string apiKey     = "1f8c669bfb6d6b86aa65400c8f3ad03d";
            const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";

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



            //NameViewModel postdata = "hulk";

            //if (postdata.Type.ToLower() == "character")
            //{
            var filter = new CharacterRequestFilter {
                NameStartsWith = "hulk"
            };

            filter.OrderBy(OrderResult.NameAscending);
            //filter.Limit = 40;
            filter.Limit = 1;


            var response = client.FindCharacters(filter);

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


            results =
                response.Data.Results.Select(res =>
                                             new CharactersInResultViewModel {
                StoryID = /*res.Stories.Items.Equals(*/ "1009351" /*).ToString()*/, /**StoryID = res.Stories. */ Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            }).ToList();



            //            else
            //            {

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


            //results =
            //            response.Data.Results.Select(res =>
            //                new CharactersInResultViewModel { StoryID = /*res.Stories.Items.Equals(*/"1009351"/*).ToString()*/,/**StoryID = res.Stories. */Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();


            List <ResultViewModel> realresults = new List <ResultViewModel>();

            //ResultViewModel realresults;


            realresults =
                response.Data.Results.Select(res =>
                                             new ResultViewModel {
                Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            }).ToList();

            realresults.FirstOrDefault();



            //else
            //{

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


            //results =
            //response.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { StoryID = /*res.Stories.Items.Equals(*/"1009351"/*).ToString()*/,/**StoryID = res.Stories. */Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();


            //}
            //else
            //{

            FindStoryCharacters();

            //ViewBag.Message = (List<CharactersInResultViewModel>)request;

            /*ViewBag.Message =*/ /*(List<CharactersInResultViewModel>)*//*request;*/

            /* ViewBag.Message =*/ /*(List<CharactersInResultViewModel>)*//*restResponse;*/


            //ViewBag.Message = results;



            //var comicFilter = new ComicRequestFilter { TitleStartsWith = "hulk" };
            //comicFilter.OrderBy(OrderResult.NameAscending);
            //comicFilter.Limit = 40;
            ////comicFilter.Limit = 1;

            //var comicFilterresponse = client.FindComics(comicFilter);

            ////if (response.Code == "200")
            ////{
            //results =
            //response.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = Marvel.Api.Model.DomainObjects.Story.*/ Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            ////}
            //var firstResultDescription = results.FirstOrDefault();

            //var characterList =

            //var characterList = firstResultDescription.Description.

            //var Filter = new StoryRequestFilter { };
            //Filter.OrderBy(OrderResult.NameAscending);
            //Filter.Limit = 40;
            ////filter.Limit = 1;

            //StoryResult storyFilterresponse = client.FindStory("1009351");  /*client.FindStoryCharacters("1009351");*/

            //resultsCharactersInAStory =
            //storyFilterresponse.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = res.Stories., */Id = res.Id, Description = res.Description/*, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL */}).ToList();
            ////    }



            //storyFilterresponse.Data.Results.

            //resultsCharactersInAStory =
            //storyFilterresponse.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = res.Stories., */Id = res.Id, Description = res.Description/*, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL */}).ToList();
            ////    }

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

            List <CharactersInResultViewModel> charactersResults = null;

            charactersResults =
                response.Data.Results.Select(res =>
                                             new CharactersInResultViewModel {
                Name = res.Name
            }).ToList();
            //    }
            //}

            var storyFilterresponseCharacterList = charactersResults;

            var baseAddress = new Uri("http://importmarvel.com/");

            using (var httpClient = new HttpClient
            {
                BaseAddress = baseAddress
            })
            {
                using (var allCharactersInAStory = /*await */ httpClient.GetAsync("api/characters"))
                {
                    string allCharactersInAStoryData = allCharactersInAStory.Result.ToString();

                    ViewBag.Message = allCharactersInAStoryData;

                    return(View(allCharactersInAStoryData));
                }

                //ViewBag.Message = allCharactersInAStoryData;

                //ViewBag.Message = realresults;

                //return View(allCharactersInAStoryData);

                //return View(realresults);



                //ViewBag.Message = results;


                //return View(results);



                //ViewBag.Message = resultsCharactersInAStory;


                //return View(resultsCharactersInAStory);



                //return View(storyFilterresponse);


                //ViewBag.Message = storyFilterresponseCharacterList;

                //return Json(storyFilterresponseCharacterList);

                //return View("Index", restResponse);

                //return View(storyFilterresponseCharacterList);

                //return Json(results);



                //[HttpPost]
                //[HttpGet]
                //public IActionResult Index(/*NameViewModel postdata*/)
                //{

                //    const string apiKey = "1f8c669bfb6d6b86aa65400c8f3ad03d";
                //    const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";

                //    const string characterName = "hulk";

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

                //    //if (postdata.Type.ToLower() == "character")
                //    //{
                //    var filter = new StoryRequestFilter { /*Characters.Equals == The Hulk*//*NameStartsWith = postdata.Name*/ };
                //    filter.OrderBy(OrderResult.NameAscending);
                //    //filter.Comics.Contains("hulk");
                //    //filter.Comics.Where(res.Id == 30)
                //    //filter.Series.
                //    filter.Limit = 1;

                //    //var response = client.FindCharacters(filter);

                //    var response = client.FindStories(filter);

                //    //if (response.Code == "200")
                //    //    {
                //    //results =
                //    //response.Data.Results./*Where(results.*//*Where(response.Data.Results.).*/Select(res =>
                //    //                //new ResultViewModel { Id = 30/*res.Id*/, Description = res.Description,  Name = "The second volume containing the Hulk\u0027s early adventures with appearances by the Sub-Mariner, the Mandarin, Ka-Zar and Nick Fury" /*res.Title*/, Url = "http://gateway.marvel.com/v1/public/stories/30" /*res.ResourceURI*/ })./*Where(response.Data.Results.Id*//*.Where(res.Id == 30)*//*.*/ToList()/*.Where(Id == 30)*//*.FirstOrDefault*//*(*//*t => t.Type == "detail").URL }).ToList(*//*)*/;
                //    //                new ResultViewModel { Id = 30, Description = res.Description, Name = res.Title, Url = "http://gateway.marvel.com/v1/public/stories/30/" })./*Where(response.Data.Results.Id*//*.Where(res.Id == 30)*//*.*/ToList()/*.Where(Id == 30)*//*.FirstOrDefault*//*(*//*t => t.Type == "detail").URL }).ToList(*//*)*/;

                //    results =
                //            response.Data.Results.Select(res =>
                //                new ResultViewModel { Id = res.Id, Description = res.Description, Name = res.Title, Url = res.ResourceURI.FirstOrDefault().ToString() }).ToList();



                //    //}.

                //    //results.Where()

                //    //else
                //    //{
                //    //    var filter = new ComicRequestFilter { TitleStartsWith = postdata.Name };
                //    //    filter.OrderBy(OrderResult.NameAscending);
                //    //    filter.Limit = 40;

                //    //    var response = client.FindComics(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/*.ToList()*/);
                //    //return View(results);
                //}

                //return View();



                //[HttpPost]
                //public JsonResult SomeActionMethod(NameViewModel postdata)
                //{
                //    const string apiKey = "1f8c669bfb6d6b86aa65400c8f3ad03d";
                //    const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";


                //    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.FindCharacters(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.FindComics(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);
                //}

                //public IActionResult Privacy()
                //{
                //    return View();
                //}
            }
        }
Esempio n. 14
0
        //     public CharacterResult FindCharacter(/*string characterId*/)
        //36         {
        //37             // Build request url
        //38             //
        //39             string requestUrl =
        //40                 string.Format("{0}/{1}", CharactersUrlSegment, "30");
        //41
        //42             var request = new RestRequest(requestUrl, Method.GET);
        //43
        //44             return /*Execute<CharacterResult>(request)*/;
        //45         }

        public IActionResult Index(/*byte[] byteBuffer*//*RestResponse restResponse*//*RestRequest request*//*NameViewModel postdata*/)
        {
            const string apiKey     = "1f8c669bfb6d6b86aa65400c8f3ad03d";
            const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";

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



            var characterRequestTest = new CharacterResult();


            //FindCharacter(")


            ///*ComicResult*/ /*Marvel.Api.MarvelRestClient.*/FindCharacterComics("30"/*,ComicRequestFilter  filter = default(ComicRequestFilter)*/);
//)



            ////NameViewModel postdata = "hulk";

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



            ///*var*/
            //CharacterResult response = (client.FindCharacters(filter))/*.AsAByteString()*/;



            //var comicFilter = new ComicRequestFilter { TitleStartsWith = "hulk" };
            //comicFilter.OrderBy(OrderResult.NameAscending);
            //comicFilter.Limit = 40;
            //comicFilter.Limit = 1;


            var comicFilter = new CharacterRequestFilter {
                NameStartsWith = "hulk"                                          /*TitleStartsWith = "hulk"*/
            };

            comicFilter.OrderBy(OrderResult.NameAscending);
            comicFilter.Limit = 40;
            //comicFilter.Limit = 1;

            var comicFilterresponse = client.FindCharacters(comicFilter);


            //ComicResult /*Marvel.Marvel.Api.*/MarvelRestClient.FindCharacterComics("30"/*,ComicRequestFilter  filter = default(ComicRequestFilter)*/);


            //var comicFilterresponse = (client.FindCharacterComics/*FindComics*/(comicFilter.ToString()));



            //if (response.Code == "200")
            //{
            results =
                comicFilterresponse.Data.Results.Select(res =>
                                                        new CharactersInResultViewModel { /*Characters = Marvel.Api.Model.DomainObjects.Story.*/
                Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            }).ToList();
            //}



            //JToken token = filter;
            //var jTokenAsString = token.AsString();

            //docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-implement-and-call-a-custom-extension-method

            /// <summary>
            /// Gets string value from JToken
            /// </summary>
            /// <param name="token"></param>
            /// <returns></returns>
            ///
            /*public */
            //            static string /*MiscExtensions.*/(this JToken token)
            //            {
            //                return token.Type == JTokenType.String ? token.Value<string>() : token.ToString();
            //            }

            //            /// <summary>
            //            /// Gets string value from JToken
            //            /// </summary>
            //            /// <param name="token"></param>
            //            /// <returns></returns>
            //            /*public */static string AsString(this JToken token, CultureInfo culture)
            //            {
            //                var value = token as JValue;
            //                if (value != null)
            //                {
            //                    return (string)value.Value.ChangeType(typeof(string), culture);
            //                }

            //                return token.Type == JTokenType.String ? token.Value<string>() : token.ToString();
            //            }

            //            /// <summary>
            //            /// Converts a byte array to a string, using its byte order mark to convert it to the right encoding.
            //            /// http://www.shrinkrays.net/code-snippets/csharp/an-extension-method-for-converting-a-byte-array-to-a-string.aspx
            //            /// </summary>
            //            /// <param name="buffer">An array of bytes to convert</param>
            //            /// <returns>The byte as a string.</returns>
            //            /*public */static string AsString(this byte[] buffer)
            //            {
            //                if (buffer == null) return "";

            //                // Ansi as default
            //                Encoding encoding = Encoding.UTF8;

            //#if FRAMEWORK
            //			return encoding.GetString(buffer);
            //#else
            //                if (buffer == null || buffer.Length == 0)
            //                    return "";

            //                /*
            //                    EF BB BF		UTF-8
            //                    FF FE UTF-16	little endian
            //                    FE FF UTF-16	big endian
            //                    FF FE 00 00		UTF-32, little endian
            //                    00 00 FE FF		UTF-32, big-endian
            //                    */

            //                if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf)
            //                {
            //                    encoding = Encoding.UTF8;
            //                }
            //                else if (buffer[0] == 0xfe && buffer[1] == 0xff)
            //                {
            //                    encoding = Encoding.Unicode;
            //                }
            //                else if (buffer[0] == 0xfe && buffer[1] == 0xff)
            //                {
            //                    encoding = Encoding.BigEndianUnicode; // utf-16be
            //                }

            //                using (MemoryStream stream = new MemoryStream())
            //                {
            //                    stream.Write(buffer, 0, buffer.Length);
            //                    stream.Seek(0, SeekOrigin.Begin);
            //                    using (StreamReader reader = new StreamReader(stream, encoding))
            //                    {
            //                        return reader.ReadToEnd();
            //                    }
            //                }
            //#endif
            //            }



            var buffer = new byte[] { };

            //buffer = (client.FindCharacters(filter));

            //var response = (client.FindCharacters(filter))/*.AsString(buffer)*/;
            /*.ToString()*//*)*//*;.Data*/

            //response.ToString();,

            //response.ToString();

            //response.AsAByteString(/*buffer*//*buffer*/);

            //var token = client.FindCharacters(filter);
            //token.ToString();



            //var jTokenAsString = token.AsString();

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



            //Commented out 10.6.2021.
            //results =
            //comicFilterresponse.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            ////}



            //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);

            ViewBag.Message = results /*comicFilterresponse*//*response*//*.ToString*//*()*/;

            ViewData["Response"] = results /*comicFilterresponse*//*response*/;

            return(View(results /*comicFilterresponse*//*response*//*response*/));
        }