public async Task <List <SpChiefExecutive> > GetChiefExecutives() { StringBuilder requestUri = new StringBuilder(_spContext.SPAppWebUrl.ToString()) .Append("_api/web/lists/getbytitle('CEO List')/items") .Append("?$select=Id,Title,TenureStartYear,TenureEndYear") .Append("&$orderby=TenureStartYear"); HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri.ToString()); request.Headers.Add("Accept", "application/json;odata=verbose"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _spContext.UserAccessTokenForSPAppWeb); HttpResponseMessage response = await client.SendAsync(request); string responseString = await response.Content.ReadAsStringAsync(); var spJsonResponse = JsonConvert.DeserializeObject <SpChiefExecutiveJsonCollection>(responseString); var ceoList = new List <SpChiefExecutive>(); foreach (var item in spJsonResponse.Data.Results) { var ceo = new SpChiefExecutive { Id = item.Id.ToString(), Name = item.Title, TenureStartYear = item.TenureStartYear, TenureEndYear = item.TenureEndYear }; ceoList.Add(ceo); } return(ceoList.OrderByDescending(c => c.TenureStartYear).ToList()); }
public async Task<List<SpChiefExecutive>> GetChiefExecutives() { StringBuilder requestUri = new StringBuilder(_spContext.SPAppWebUrl.ToString()) .Append("_api/web/lists/getbytitle('CeoList')/items") .Append("?$select=Id,Title,TenureStartYear,TenureEndYear") .Append("&$orderby=TenureStartYear"); HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri.ToString()); request.Headers.Add("Accept", "application/json;odata=verbose"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _spContext.UserAccessTokenForSPAppWeb); HttpResponseMessage response = await client.SendAsync(request); string responseString = await response.Content.ReadAsStringAsync(); var spJsonResponse = JsonConvert.DeserializeObject<SpChiefExecutiveJsonCollection>(responseString); var ceoList = new List<SpChiefExecutive>(); foreach (var item in spJsonResponse.Data.Results) { var ceo = new SpChiefExecutive { Id = item.Id.ToString(), Name = item.Title, TenureStartYear = item.TenureStartYear, TenureEndYear = item.TenureEndYear }; ceoList.Add(ceo); } return ceoList.OrderByDescending(c => c.TenureStartYear).ToList(); }