public async Task AddAsync(LocalScan ls) { await LocalScans.InsertOneAsync(ls); }
public async Task AddAsync(LocalScan ls) { await _localScanRepository.AddAsync(ls); }
public static async Task <LocalScan> ReturnFormattedLocalScan(HashSet <BasicCharacter> Characters, string id) { var client = new RestClient("https://esi.evetech.net"); var request = new RestRequest("latest/characters/affiliation/", Method.POST); request.AddHeader("Accept", "application/json"); request.Parameters.Clear(); var Ids = new HashSet <int>(); foreach (var character in Characters) { Ids.Add(character.id); } var strJSONContent = Newtonsoft.Json.JsonConvert.SerializeObject(Ids); request.AddParameter("application/json", strJSONContent, ParameterType.RequestBody); //var response = client.Execute(request); var response = await client.PostAsync <List <ComplexCharacter> >(request); //dynamic affiliations = Newtonsoft.Json.JsonConvert.DeserializeObject(response.Content); var ListOfAllianceIds = new HashSet <int>(); var ListOfCorporationIds = new HashSet <int>(); foreach (var a in response) { if (a.alliance_id != 0) { ListOfAllianceIds.Add(Convert.ToInt32(a.alliance_id)); } ListOfCorporationIds.Add(Convert.ToInt32(a.corporation_id)); } var request2 = new RestRequest("legacy/corporations/{id}", Method.GET); var request3 = new RestRequest("latest/alliances/{id}", Method.GET); var allianceCount = new HashSet <AllianceCount>(); var corporationCount = new HashSet <CorporationCount>(); var dict = new Dictionary <int, string>(); foreach (var c in ListOfCorporationIds) { try { Console.WriteLine("New corp..." + " " + c); request2.Parameters.Clear(); request2.AddUrlSegment("id", c); var response2 = await client.GetAsync <Corporation>(request2); Console.WriteLine(response2.corporation_name + ": " + c); dict.Add(c, response2.corporation_name); var cc = new CorporationCount(); cc.CorpName = response2.corporation_name; cc.CorpId = c; cc.CorpCount = 0; corporationCount.Add(cc); } catch { continue; } } foreach (var a in ListOfAllianceIds) { try { request3.Parameters.Clear(); request3.AddUrlSegment("id", a); var response3 = await client.GetAsync <AllianceDTO>(request3); dict.Add(a, response3.name); var ac = new AllianceCount(); ac.AllyName = response3.name; ac.AllyId = a; ac.AllyCount = 0; allianceCount.Add(ac); } catch { continue; } } foreach (var a in response) { try { if (a.alliance_id != 0) { var ac = allianceCount.FirstOrDefault(x => x.AllyName == dict[Convert.ToInt32(a.alliance_id)]); ac.AllyCount++; } var cc = corporationCount.FirstOrDefault(x => x.CorpName == dict[Convert.ToInt32(a.corporation_id)]); cc.CorpCount++; } catch { continue; } } var corpSorted = new HashSet <CorporationCount>(); foreach (var c in corporationCount.OrderByDescending(x => x.CorpCount)) { corpSorted.Add(c); } var allySorted = new HashSet <AllianceCount>(); foreach (var a in allianceCount.OrderByDescending(x => x.AllyCount)) { allySorted.Add(a); } var ToReturn = new LocalScan(id, Characters, corpSorted, allySorted); return(ToReturn); }