public async Task <ActionResult> AddMemberAsync(List <string> selectedMember) { var groupId = TempData["GroupId"]; try { if (selectedMember != null) { if (selectedMember.Any() && groupId != null) { var groupMemberAssignModel = new GroupMemberAssignModel(); groupMemberAssignModel.GroupId = groupId.ToString(); groupMemberAssignModel.SelectedMembers = selectedMember; await _groupMemberService.AddGroupMembers(groupMemberAssignModel); } } return(RedirectToAction(nameof(Index), new { id = groupId.ToString() })); } catch (Exception ex) { _logger.LogError($"GroupMembersController-AddMemberAsync: Exception occurred ...."); _logger.LogError(ex); return(RedirectToAction(nameof(Index), new { id = groupId.ToString() })); } }
public async Task <GroupModel> CreateGroup(GroupModel groupModel) { try { _logger.LogInfo("GroupService-CreateGroup: [Started] creation of group in Azure AD B2C"); if (groupModel == null) { _logger.LogError("GroupService-CreateGroup: Group Model cannot be null..."); return(null); } var client = GraphClientUtility.GetGraphServiceClient(); if (client == null) { _logger.LogError("GroupService-CreateGroup: Unable to create object for graph client "); return(null); } var group = BuildGroup(groupModel); var newGroup = await client.Groups.Request().AddAsync(group); var newGroupModel = GraphClientUtility.ConvertGraphGroupToGroupModel(newGroup, _logger); if (newGroupModel != null) { var groupId = newGroup.Id; if (!string.IsNullOrEmpty(groupId)) { #region Assign Members if (groupModel.OwnerSelected.Any()) { _logger.LogInfo($"GroupService-CreateGroup: assigning {groupModel.OwnerSelected.Count()} owner(s) for group {newGroupModel.DisplayName} in Azure AD B2C"); var groupOwnerAssign = new GroupOwnerAssignModel { GroupId = groupId, SelectedOwners = groupModel.OwnerSelected }; await _groupOwnerService.AddGroupOwners(groupOwnerAssign); _logger.LogInfo($"GroupService-CreateGroup: assigned {groupModel.OwnerSelected.Count()} owner(s) for group {newGroupModel.DisplayName} in Azure AD B2C"); } if (groupModel.MemberSelected.Any()) { _logger.LogInfo($"GroupService-CreateGroup: assigning {groupModel.MemberSelected.Count()} member(s) for group {newGroupModel.DisplayName} in Azure AD B2C"); var groupMemberAssign = new GroupMemberAssignModel { GroupId = groupId, SelectedMembers = groupModel.MemberSelected }; await _groupMemberService.AddGroupMembers(groupMemberAssign); _logger.LogInfo($"GroupService-CreateGroup: assigned {groupModel.MemberSelected.Count()} member(s) for group {newGroupModel.DisplayName} in Azure AD B2C"); } #endregion } } _logger.LogInfo("GroupService-CreateGroup: [Completed] creation of group in Azure AD B2C"); return(newGroupModel); } catch (Exception ex) { _logger.LogError("GroupService-CreateGroup: Exception occured...."); _logger.LogError(ex); throw ex; } }