예제 #1
0
        public async Task <IActionResult> GetBlade()
        {
            using (var client = new HttpClient())
            {
                // Update url in the following line.
                client.BaseAddress = new Uri("http://monsterhunterapi.azurewebsites.net");
                var response = await client.GetAsync("/api/blade");

                response.EnsureSuccessStatusCode();
                var stringResult = await response.Content.ReadAsStringAsync();

                //deserialized.
                var deserialized = WeaponsResult.FromJson(stringResult);
                foreach (var x in deserialized)
                {
                    Weapons weapon = new Weapons
                    {
                        WeaponName = x.Name,
                        WeaponID   = (int)x.Id
                    };
                    _context.Weapons.Add(weapon);
                }
                _context.SaveChanges();
                return(View(deserialized));
            }
        }
예제 #2
0
        public async Task <IActionResult> FilterBlade(string weaponClass, string element, int rarity)
        {
            using (var client = new HttpClient())
            {
                // Update url in the following line.
                client.BaseAddress = new Uri("http://monsterhunterapi.azurewebsites.net");
                var response = await client.GetAsync($"/api/blade/{weaponClass}?{element}?{rarity}");

                response.EnsureSuccessStatusCode();
                var stringResult = await response.Content.ReadAsStringAsync();

                //deserialized.
                var deserialized = WeaponsResult.FromJson(stringResult);

                return(View(deserialized));
            }
        }