public Task<IEnumerable<CardInfo>> Handle(FindCardInfoByNameQuery query) { return Task.FromResult(new List<CardInfo> { new CardInfo { Name = "Baron Sengir" }, new CardInfo { Name = "Auntie Em" }, }.AsEnumerable()); }
public async Task<IEnumerable<CardInfo>> Handle(FindCardInfoByNameQuery query) { var uri = new Uri("https://api.mtgapi.com/v2/cards") .AddQuery("name", query?.Name); var request = WebRequest.Create(uri); using (var response = await request.GetResponseAsync()) using (var stream = response.GetResponseStream()) using (var reader = new StreamReader(stream)) { var body = await reader.ReadToEndAsync(); try { var apiResponseObj = JsonConvert.DeserializeObject<MtgApi.Models.CardInformationResponse>(body); return apiResponseObj.Cards.Select(c => new Models.CardInfo { Name = c.Name }); } catch (Exception ex) { Debugger.Break(); throw; } } }