public async Task <string> GetDnDSpell(string spellName, float?spellLevel, string spellClass, string spellRange, bool?spellConcertration, string spellDamageType) { SpellDamageModel spellDamageTypeObject = null; List <DndDatabaseLinkModel> spellClassList = null; if (spellClass != null) { var spellClassModel = new DndDatabaseLinkModel() { Name = spellClass }; spellClassList = new List <DndDatabaseLinkModel>(); spellClassList.Add(spellClassModel); } if (spellDamageType != null) { spellDamageTypeObject = new SpellDamageModel() { damageType = new DndDatabaseLinkModel { Name = spellDamageType } }; } var spellModel = new DndSpellModel() { Name = spellName, Level = spellLevel, Classes = spellClassList, Range = spellRange, Concentration = spellConcertration, Damage = spellDamageTypeObject }; var answer = await _dndAPISpellService.GetSpellByName(spellModel); return(answer); }
public async Task <string> GetSpellByName(DndSpellModel spellModel) { var spellClient = _clientFactory.CreateClient(DND_API); var serializer = new JsonSerializer() { NullValueHandling = NullValueHandling.Ignore }; var stringWriter = new StringWriter(); using (var writer = new JsonTextWriter(stringWriter)) { writer.QuoteName = false; serializer.Serialize(writer, spellModel); } var query = "query{ spells(filter:" + stringWriter.ToString() + "){name}}"; var request = new HttpRequestMessage(HttpMethod.Get, "/graphql"); request.Content = new StringContent(query, Encoding.UTF8, "application/json"); var DnDAPI = await spellClient.GetAsync("/graphql/?query=" + query); return(await DnDAPI.Content.ReadAsStringAsync()); }