public GraphSharePointAppService( ILogger <GraphSharePointBaseService> logger, IOptionsMonitor <AppOptions> appOptions, IGraphClientAppContext graphClientContext, SharePointListsSchemaHelper sharePointListsSchemaHelper) : base(logger, appOptions, graphClientContext) { }
public async Task CreateAllListsAsync(string siteRootId, string requestId = "") { _logger.LogInformation($"RequestId: {requestId} - SetupService_CreateAllListsAsync called."); var sharepointLists = GetSharePointLists(); var siteList = new SiteList(); siteList.SiteId = siteRootId; foreach (var list in sharepointLists) { try { string htmlBody = string.Empty; switch (list) { case ListSchema.OpportunitiesListId: htmlBody = SharePointListsSchemaHelper.OpportunitiesJsonSchema(_appOptions.OpportunitiesListId); break; case ListSchema.Permissions: htmlBody = SharePointListsSchemaHelper.PermissionJsonSchema(_appOptions.Permissions); break; case ListSchema.ProcessListId: htmlBody = SharePointListsSchemaHelper.WorkFlowItemsJsonSchema(_appOptions.ProcessListId); break; case ListSchema.OpportunityMetaDataId: htmlBody = SharePointListsSchemaHelper.OpportunityMetaDataJsonSchema(_appOptions.OpportunityMetaDataId); break; case ListSchema.RoleListId: htmlBody = SharePointListsSchemaHelper.RoleJsonSchema(_appOptions.RoleListId); break; case ListSchema.GroupsListId: htmlBody = SharePointListsSchemaHelper.GroupJsonSchema(_appOptions.GroupsListId); break; case ListSchema.TemplateListId: htmlBody = SharePointListsSchemaHelper.TemplatesJsonSchema(_appOptions.TemplateListId); break; case ListSchema.DashboardListId: htmlBody = SharePointListsSchemaHelper.DashboardJsonSchema(_appOptions.DashboardListId); break; case ListSchema.TasksListId: htmlBody = SharePointListsSchemaHelper.TasksJsonSchema(_appOptions.TasksListId); break; } await _graphSharePointAppService.CreateSiteListAsync(htmlBody, siteRootId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - SetupService_CreateAllListsAsync error: {ex}"); } } }
private async Task CreateSiteListAsync() { try { // TODO Optional: see how we can just leverage code in GraphSharePointService var htmlBody = SharePointListsSchemaHelper.GetGroupMembershipJsonSchema(_timeTrackerOptions.SharePointGroupId); var requestUrl = _timeTrackerOptions.GraphRequestUrl + "/sites/" + _timeTrackerOptions.SharePointSiteId + "/lists"; // Create the request message and add the content. HttpRequestMessage hrm = new HttpRequestMessage(HttpMethod.Post, requestUrl); hrm.Content = new StringContent(htmlBody, System.Text.Encoding.UTF8, "application/json"); // Authenticate (add access token) our HttpRequestMessage await GraphAppClient.AuthenticationProvider.AuthenticateRequestAsync(hrm); // Send the request and get the response. HttpResponseMessage response = await GraphAppClient.HttpProvider.SendAsync(hrm); // Get the content from the response. if (response.StatusCode != System.Net.HttpStatusCode.Created) { //var content = await response.Content.ReadAsStringAsync(); // TODO: Depending on code, rise proper exception for now invalid request is throw new ServiceException(new Error { Code = ErrorConstants.Codes.InvalidRequest, Message = response.StatusCode.ToString() }); } } catch (ServiceException ex) { switch (ex.Error.Code) { case "Request_ResourceNotFound": case "ResourceNotFound": case "ErrorItemNotFound": case "itemNotFound": throw; case "TokenNotFound": //await HttpContext.ChallengeAsync(); throw; default: throw; } } }
public async Task CreateAllListsAsync(string siteRootId, string requestId = "") { _logger.LogInformation($"RequestId: {requestId} - SetupService_CreateAllListsAsync called."); var sharepointLists = GetSharePointLists(); var siteList = new SiteList(); siteList.SiteId = _appOptions.ProposalManagementRootSiteId; if (string.IsNullOrEmpty(siteList.SiteId)) { siteList.SiteId = siteRootId; } foreach (var list in sharepointLists) { try { string htmlBody = string.Empty; switch (list) { case ListSchema.CategoriesListId: htmlBody = SharePointListsSchemaHelper.CategoriesJsonSchema(_appOptions.CategoriesListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.IndustryListId: htmlBody = SharePointListsSchemaHelper.IndustryJsonSchema(_appOptions.IndustryListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.OpportunitiesListId: htmlBody = SharePointListsSchemaHelper.OpportunitiesJsonSchema(_appOptions.OpportunitiesListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.Permissions: htmlBody = SharePointListsSchemaHelper.PermissionJsonSchema(_appOptions.Permissions); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.ProcessListId: htmlBody = SharePointListsSchemaHelper.WorkFlowItemsJsonSchema(_appOptions.ProcessListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.RegionsListId: htmlBody = SharePointListsSchemaHelper.RegionsJsonSchema(_appOptions.RegionsListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.RoleListId: htmlBody = SharePointListsSchemaHelper.RoleJsonSchema(_appOptions.RoleListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.RoleMappingsListId: htmlBody = SharePointListsSchemaHelper.RoleMappingsJsonSchema(_appOptions.RoleMappingsListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.TemplateListId: htmlBody = SharePointListsSchemaHelper.TemplatesJsonSchema(_appOptions.TemplateListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.DashboardListId: htmlBody = SharePointListsSchemaHelper.DashboardJsonSchema(_appOptions.DashboardListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; case ListSchema.TasksListId: htmlBody = SharePointListsSchemaHelper.TasksJsonSchema(_appOptions.TasksListId); await _graphSharePointAppService.CreateSiteListAsync(htmlBody); break; } } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - SetupService_CreateAllListsAsync error: {ex}"); } } }
public async Task CreateSiteListAsync(SiteList siteList, ListSchema listSchema) { try { if (String.IsNullOrEmpty(siteList.ListId)) { throw new ArgumentNullException(nameof(siteList.ListId)); } if (String.IsNullOrEmpty(siteList.SiteId)) { throw new ArgumentNullException(nameof(siteList.SiteId)); } var htmlBody = ""; switch (listSchema) { case ListSchema.NotificationsListSchema: htmlBody = SharePointListsSchemaHelper.GetNotificationsJsonSchema(siteList.ListId); break; case ListSchema.ReportHoursListSchema: htmlBody = SharePointListsSchemaHelper.GetReportHoursJsonSchema(siteList.ListId); break; case ListSchema.TeamHoursListSchema: htmlBody = SharePointListsSchemaHelper.GetTeamHoursJsonSchema(siteList.ListId); break; case ListSchema.WorkHoursListSchema: htmlBody = SharePointListsSchemaHelper.GetWorkHoursJsonSchema(siteList.ListId); break; case ListSchema.UsersListSchema: htmlBody = SharePointListsSchemaHelper.GetUsersMembershipJsonSchema(siteList.ListId); break; case ListSchema.TotalHrsListSchema: htmlBody = SharePointListsSchemaHelper.GetTotalHoursJsonSchema(siteList.ListId); break; } var requestUrl = _timeTrackerOptions.GraphRequestUrl + "/sites/" + siteList.SiteId + "/lists"; // Create the request message and add the content. HttpRequestMessage hrm = new HttpRequestMessage(HttpMethod.Post, requestUrl); hrm.Content = new StringContent(htmlBody, System.Text.Encoding.UTF8, "application/json"); var response = new HttpResponseMessage(); // Authenticate (add access token) our HttpRequestMessage await GraphAppClient.AuthenticationProvider.AuthenticateRequestAsync(hrm); // Send the request and get the response. response = await GraphAppClient.HttpProvider.SendAsync(hrm); // Get the content from the response. if (response.StatusCode != System.Net.HttpStatusCode.Created) { // TODO: Depending on code, rise proper exception for now invalid request is throw new ServiceException(new Error { Code = ErrorConstants.Codes.InvalidRequest, Message = response.StatusCode.ToString() }); } } catch (ServiceException ex) { switch (ex.Error.Code) { case "Request_ResourceNotFound": case "ResourceNotFound": case "ErrorItemNotFound": case "itemNotFound": throw; case "TokenNotFound": //await HttpContext.ChallengeAsync(); throw; default: throw; } } }