示例#1
0
        public async Task <IActionResult> Character(string Param)
        {
            List <SuperHeroViewModel.Result> data = new List <SuperHeroViewModel.Result>();

            try
            {
                Param = Param ?? "0";
                var PalabraBUscada           = Param;
                SuperHeroViewModel.Root list = new SuperHeroViewModel.Root();
                HttpResponseMessage     res;


                HttpClient client = _api.Finder(Param);
                if (!_cache.TryGetValue(PalabraBUscada, out data))
                {
                    if (data == null)
                    {
                        res = await client.GetAsync("");

                        if (res.IsSuccessStatusCode)
                        {
                            var result = res.Content.ReadAsStringAsync().Result;
                            list = JsonConvert.DeserializeObject <SuperHeroViewModel.Root>(result);
                        }
                        if (list.response == "error")
                        {
                            data = (_Util.getNotResult("NO RESULT"));
                        }
                        else
                        {
                            if (_Util.IsNumeric(Param))
                            {
                                data = (_Util.getResultForNumber(list));
                            }
                            else
                            {
                                data = (list.results);
                            }
                        }
                    }
                    var cacheConf = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(60));
                    _cache.Set(PalabraBUscada, data, cacheConf);
                }
                return(View(data));
            }
            catch (Exception)
            {
                data = (_Util.getNotResult("ERROR, CONTACT THE ADMIN"));
                return(View(data));
            }
        }
示例#2
0
 public List <SuperHeroViewModel.Result> getResultForNumber(SuperHeroViewModel.Root list)
 {
     try
     {
         List <SuperHeroViewModel.Result> lista = new List <SuperHeroViewModel.Result>();
         SuperHeroViewModel.Result        model = new SuperHeroViewModel.Result();
         model.name        = list.name;
         model.image       = list.image;
         model.powerstats  = list.powerstats;
         model.id          = list.id;
         model.work        = list.work;
         model.appearance  = list.appearance;
         model.biography   = list.biography;
         model.connections = list.connections;
         lista.Add(model);
         return(lista);
     }
     catch (Exception)
     {
         throw;
     }
 }