/// <summary> /// Shorthand extension encapsulating Convert.ToInt16() allowing /// syntax changes from this: /// ...Convert.ToInt16(doubleValue)... /// to: /// ...doubleValue.ToInt16()... /// </summary> /// <param name="dbl">The double value to convert.</param> /// <returns>The value as Int16 format.</returns> public static List <Dictionary <string, string> > ToDictionary(this ListItemsCollectionPage items) { List <Dictionary <string, string> > lst = new List <Dictionary <string, string> >(); foreach (ListItem item in items) { //lst.Add( item.Fields.AdditionalData["Title"]) } // Microsoft.Graph.GraphServiceClient client = new Microsoft.Graph.GraphServiceClient(auth); // var i = client.Sites[""].Lists[""].Items.Request().GetAsync(); return(lst); }
public async Task <List <GraphResultItem> > GetSiteListItemsAsync(SiteList siteList, IEnumerable <QueryOption> queryOptions) { try { if (String.IsNullOrEmpty(siteList.ListId)) { throw new ArgumentNullException(nameof(siteList.ListId)); } if (String.IsNullOrEmpty(siteList.SiteId)) { throw new ArgumentNullException(nameof(siteList.SiteId)); } if (queryOptions == null) { throw new ArgumentNullException(nameof(queryOptions)); } var listItemResults = new List <ListItem>(); var options = queryOptions.ToList <QueryOption>(); // Call to graph API to retrieve List Items filtered by dateQuery (match pattern: yyyyMMdd) example: for full month 201802 var graphResponse = new ListItemsCollectionPage(); graphResponse = (ListItemsCollectionPage)await GraphAppClient.Sites[siteList.SiteId].Lists[siteList.ListId].Items.Request(options).Expand("fields").GetAsync();//.Items.Request(options).Expand("fields").GetAsync(); if (graphResponse == null) { throw new ServiceException(new Error { Code = ErrorConstants.Codes.ItemNotFound }); } listItemResults.AddRange(graphResponse); while (graphResponse.NextPageRequest != null) { graphResponse = (ListItemsCollectionPage)await graphResponse.NextPageRequest.GetAsync(); listItemResults.AddRange(graphResponse); } if (listItemResults?.Count == 0) { throw new ServiceException(new Error { Code = ErrorConstants.Codes.ItemNotFound }); } var resultItems = new List <GraphResultItem>(); foreach (var item in listItemResults) { var resultsItemProperties = new Dictionary <string, object>(); foreach (var field in item.Fields.AdditionalData) { resultsItemProperties.Add(field.Key, field.Value.ToString()); } resultItems.Add(new GraphResultItem { Id = item.Id, Properties = resultsItemProperties }); } return(resultItems); } catch (ServiceException ex) { switch (ex.Error.Code) { case "Request_ResourceNotFound": case "ResourceNotFound": case "ErrorItemNotFound": case "itemNotFound": return(new List <GraphResultItem>()); case "ErrorInvalidUser": throw; case "AuthenticationFailure": throw; case "TokenNotFound": //await HttpContext.ChallengeAsync(); throw; default: throw; } } }