public async Task <TitleListResponseModel> GetTitlesList() { //NameValueCollection query = new NameValueCollection(); //query["indexes"] = "Title"; //query["page"] = "1"; Dictionary <string, string> query = new Dictionary <string, string>(); query.Add("indexes", "title"); query.Add("page", "1"); TitleListResponseModel result = new TitleListResponseModel(); HttpClientResponse clientResponse = await TryGetResponseAsync("search", query); if (clientResponse.HasError) { return(new TitleListResponseModel() { Error = true, Message = clientResponse.Message }); } else { TitleListResponseModel temp = JsonConvert.DeserializeObject <TitleListResponseModel>(clientResponse.Message); result.Results.AddRange(temp.Results); while (temp.Pagination.PageNext.HasValue) // for (int p = 2; p <= temp.Pagination.PageNext; p++) { query["page"] = $"{temp.Pagination.PageNext}"; clientResponse = await TryGetResponseAsync("search", query); if (clientResponse.HasError) { return(new TitleListResponseModel() { Error = true, Message = clientResponse.Message }); } else { temp = JsonConvert.DeserializeObject <TitleListResponseModel>(clientResponse.Message); result.Results.AddRange(temp.Results); } } return(result); } }
public static async Task SeedDatabase(MasterSpriggansDatabaseContext context, XIVApi xivApi) { // Get the list of titles from the XIVApi Logger.Message("Downloading title list, this may take a moment..."); TitleListResponseModel titleListResponse = await xivApi.GetTitlesList(); if (titleListResponse.Error.HasValue) { throw new Exception(titleListResponse.Message); } else { Logger.Message("Inserting titles into database..."); foreach (var title in titleListResponse.Results) { await context.AddAsync(new XIVTitleModel() { ID = title.ID, Name = title.Name }); } await context.SaveChangesAsync(); } }