public async Task <ActionResult> GroupMemberDelete(List <string> selectedUser) { var id = string.Empty; try { var groupId = TempData["GroupId"]; if (groupId != null) { id = groupId.ToString(); if (selectedUser != null) { if (selectedUser.Any()) { var val = new GroupMemberAssignModel(); val.GroupId = id; val.SelectedMembers = selectedUser; await _groupMemberService.RemoveGroupMembers(val); return(RedirectToAction(nameof(Index), new { id = id })); } } } } catch (Exception ex) { _logger.LogError($"GroupOwnersController-GroupOwnerDelete: Exception occurred ...."); _logger.LogError(ex); } return(RedirectToAction(nameof(Index), new { id = id })); }
public async Task <ActionResult> OnPostGroupMemberDelete([FromBody] GroupMemberAssignModel groupMemberAssign) { try { if (groupMemberAssign != null) { if (groupMemberAssign.SelectedMembers != null) { if (groupMemberAssign.SelectedMembers.Any() && !string.IsNullOrEmpty(groupMemberAssign.GroupId)) { HttpClient httpClient = new HttpClient(); var url = $"{CareStreamConst.Base_Url}{CareStreamConst.Base_API}{CareStreamConst.GroupMember_Url}"; httpClient.BaseAddress = new Uri(CareStreamConst.Base_Url); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, new Uri(url)); var payload = JsonConvert.SerializeObject(groupMemberAssign); request.Content = new StringContent(payload, Encoding.UTF8, CareStreamConst.Application_Json); var result = await httpClient.SendAsync(request); if (result.IsSuccessStatusCode) { var data = await result.Content.ReadAsStringAsync(); } } } } } catch (Exception ex) { Console.WriteLine(ex); } return(this.RedirectToAction("OnGetAsync")); }
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 <IActionResult> Post([FromBody] GroupMemberAssignModel groupMemberAssignModel) { try { if (groupMemberAssignModel == null) { _logger.LogError("GroupMembersController-Post: Group Member cannot be null..."); return(NotFound()); } _logger.LogInfo("GroupMembersController-Post: [Started] assigning member to group in Azure AD B2C"); if (!string.IsNullOrEmpty(groupMemberAssignModel.GroupId) && groupMemberAssignModel.SelectedMembers.Any()) { var client = GraphClientUtility.GetGraphServiceClient(); if (client == null) { _logger.LogError("GroupMembersController-Post: Unable to create object for graph client "); return(NotFound()); } // Get all user from Graph var users = await client.Users.Request().GetAsync(); if (users != null) { var assigningUsers = users.Where(x => groupMemberAssignModel.SelectedMembers.Contains(x.Id)).ToList(); if (assigningUsers != null) { foreach (var assignUser in assigningUsers) { try { await client.Groups[groupMemberAssignModel.GroupId].Members.References.Request().AddAsync(assignUser); } catch (Exception ex) { _logger.LogError($"GroupMembersController-Post: unable to assign member [{assignUser.UserPrincipalName}] to the group [id:{groupMemberAssignModel.GroupId}]"); _logger.LogError(ex); } } } } } _logger.LogInfo("GroupMembersController-Post: [Completed] assigning member(s) to group in Azure AD B2C"); return(Ok()); } catch (Exception ex) { _logger.LogError("GroupMembersController-Post: Exception occured...."); _logger.LogError(ex); throw ex; } }
public async Task <IActionResult> Delete([FromBody] GroupMemberAssignModel val) { try { if (val == null) { _logger.LogError("GroupMembersController-Delete: Input value cannot be empty"); return(NotFound()); } var groupId = val.GroupId; if (!string.IsNullOrEmpty(groupId)) { GraphServiceClient client = GraphClientUtility.GetGraphServiceClient(); if (client == null) { _logger.LogError("GroupMembersController-Delete: Unable to create object for graph client"); return(NotFound()); } _logger.LogInfo($"GroupMembersController-Delete: [Started] unassigning member(s) for group [Id:{groupId}]"); foreach (var memberId in val.SelectedMembers) { try { _logger.LogInfo($"GroupMembersController-Delete: Removing member [{memberId}] from group [Id:{groupId}] on Azure AD B2C"); await client.Groups[groupId].Members[memberId].Reference.Request().DeleteAsync(); _logger.LogInfo($"GroupMembersController-Delete: Removed member [{memberId}] from group [Id:{groupId}] on Azure AD B2C"); } catch (Exception ex) { _logger.LogError($"GroupMembersController-Delete: Exception occured while unassigning member [Id:{memberId}] for group [Id:{groupId}] "); _logger.LogError(ex); } } _logger.LogInfo($"GroupMembersController-Delete: [Completed] unassigning member(s) from group [Id:{val.GroupId}]"); } return(Ok()); } catch (Exception ex) { _logger.LogError("GroupMembersController-Delete: Exception occured...."); _logger.LogError(ex); throw ex; } }
public void AddSelectedOwnerOrMember([FromBody] GroupMemberAssignModel groupMemberAssign) { if (groupMemberAssign != null) { if (groupMemberAssign.SelectedMembers != null && !string.IsNullOrEmpty(groupMemberAssign.GroupId)) { switch (groupMemberAssign.GroupId) { case CareStreamConst.Member: TempData[CareStreamConst.GroupMember] = groupMemberAssign.SelectedMembers; break; case CareStreamConst.Owner: TempData[CareStreamConst.GroupOwner] = groupMemberAssign.SelectedMembers; break; } } } }
public async Task <IActionResult> OnPostAddMember(List <string> selectedMember) { var id = string.Empty; try { id = GetGroupIdFromQuery("id"); if (selectedMember != null) { if (selectedMember.Any() && !string.IsNullOrEmpty(id)) { groupMemberAssignModel = new GroupMemberAssignModel(); groupMemberAssignModel.GroupId = id; groupMemberAssignModel.SelectedMembers = selectedMember; HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(CareStreamConst.Base_Url); var payload = JsonConvert.SerializeObject(groupMemberAssignModel); StringContent content = new StringContent(payload, Encoding.UTF8, CareStreamConst.Application_Json); var result = await httpClient.PostAsync($"{CareStreamConst.Base_API}{CareStreamConst.GroupMember_Url}", content); if (result.IsSuccessStatusCode) { var data = await result.Content.ReadAsStringAsync(); } } } } catch (Exception ex) { Console.WriteLine(ex); } return(this.RedirectToAction("OnGetAsync", id)); }
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; } }