public async Task CreateAdminGroupAsync(string name, string requestId = "") { _logger.LogInformation($"RequestId: {requestId} - SetupService_CreateAdminGroupAsync called."); try { await _graphTeamsAppService.CreateGroupAsync(name, name + " Group"); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - SetupService_CreateAdminGroupAsync error: {ex}"); throw; } }
public async Task <StatusCodes> CreateItemAsync(Role entity, string requestId = "") { _logger.LogInformation($"RequestId: {requestId} - RolesRepo_CreateItemAsync called."); try { if (!(await CheckRoleAdGroupNameExist(entity.AdGroupName.Trim(), requestId))) { try { await _graphTeamsAppService.CreateGroupAsync(entity.AdGroupName.Trim(), entity.AdGroupName.Trim() + " Group"); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - SetupService_CreateAdminGroupAsync error: {ex}"); } } var siteList = new SiteList { SiteId = _appOptions.ProposalManagementRootSiteId, ListId = _appOptions.RoleListId }; // Create Json object for SharePoint create list item dynamic itemFieldsJson = new JObject(); dynamic itemJson = new JObject(); itemFieldsJson.AdGroupName = entity.AdGroupName.Trim(); itemFieldsJson.Role = entity.DisplayName.Trim(); itemFieldsJson.TeamsMembership = entity.TeamsMembership.Name.ToString(); itemFieldsJson.Permissions = JsonConvert.SerializeObject(entity.Permissions, Formatting.Indented); itemJson.fields = itemFieldsJson; await _graphSharePointAppService.CreateListItemAsync(siteList, itemJson.ToString(), requestId); _logger.LogInformation($"RequestId: {requestId} - RolesRepo_CreateItemAsync finished creating SharePoint list item."); await SetCacheAsync(requestId); return(StatusCodes.Status201Created); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - RolesRepo_CreateItemAsync error: {ex}"); throw; } }
public async Task CreateAdminGroupAsync(string name, string requestId = "") { _logger.LogInformation($"RequestId: {requestId} - SetupService_CreateAdminGroupAsync called."); try { await _graphTeamsAppService.CreateGroupAsync(name, name + " Group"); //get groupID bool check = true; dynamic jsonDyn = null; var groupName = WebUtility.UrlEncode(name); var options = new List <QueryParam>(); options.Add(new QueryParam("filter", $"startswith(displayName,'{groupName}')")); while (check) { var groupIdJson = await _graphUserAppService.GetGroupAsync(options, "", requestId); jsonDyn = groupIdJson; JArray jsonArray = JArray.Parse(jsonDyn["value"].ToString()); if (jsonArray.Count() > 0) { if (!String.IsNullOrEmpty(jsonDyn.value[0].id.ToString())) { check = false; } } } var groupID = String.Empty; groupID = jsonDyn.value[0].id.ToString(); //get user Id string objectId = _userContext.User.FindFirst(AzureAdConstants.ObjectIdClaimType).Value; await _graphUserAppService.AddGroupMemberAsync(objectId, groupID, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - SetupService_CreateAdminGroupAsync error: {ex}"); throw; } }