public static void CreateGroup(IOrganizationService service, ITracingService trace, Entity entity, Entity image) { try { // Check if the entity contains status and email attributes if (!image.Contains(CrmContext.Account.NameNl) || !image.Contains(CrmContext.Base.StateCode)) { return; } trace.Trace("Start processing group creation"); var status = entity.GetAttributeValue <OptionSetValue>(CrmContext.Base.StateCode); // Check if status is active if (status.Value == CrmContext.StateCodes.Active) { trace.Trace("Status of account is active"); trace.Trace("Retrieve account information"); var accountId = image.GetAttributeValue <Guid>(CrmContext.Account.Id); var accountName = image.GetAttributeValue <string>(CrmContext.Account.NameNl); trace.Trace("Sending group request to the API"); // Create invite var groupRequest = new GroupRequestDTO { AccountId = accountId.ToString(), AccountName = accountName }; SendGroupRequest(service, trace, groupRequest); } } catch (FaultException <OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException( $"An error occurrd in the organizationservice. {ex.Detail.Message}"); } catch (TimeoutException ex) { throw new InvalidPluginExecutionException($"A timeout occurred. {ex.Message}"); } catch (FaultException ex) { throw new InvalidPluginExecutionException($"An error occurrd. {ex.Message}"); } }
private static void SendGroupRequest(IOrganizationService service, ITracingService trace, GroupRequestDTO request) { //Get the application settings var xFunctionKey = SettingHelper.RetrieveSetting(trace, SettingHelper.SecureConfigKeys.GroupFunctionKey); var xFunctionEndPoint = SettingHelper.RetrieveSetting(trace, SettingHelper.SecureConfigKeys.GroupEndPoint); trace.Trace($"Sending request to Invite Azure Function: {xFunctionEndPoint}"); // Call mail API via APIM. using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("x-functions-key", xFunctionKey); var content = new StringContent(GlobalHelper.JsonSerializer <GroupRequestDTO>(request), Encoding.UTF8, "application/json"); var response = httpClient.PostAsync( xFunctionEndPoint, content).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { trace.Trace($"Success: group request is successfully send."); } else { var errorContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); trace.Trace($"Error: group request failed - {errorContent}"); } } }
public IActionResult PendingRequests(Guid Id) { try { var CurrentUser = _context.Users.Find(userManager.GetUserId(User)); if (CurrentUser is null) { throw new DomainException(ErrorMessages.NotSignedIn); } var existingAccount = _userStore.GetByIdentityUserId(CurrentUser.Id); if (existingAccount.AccountStatus.Equals(Status.Suspended)) { signInManager.SignOutAsync(); } var existingGroup = _GroupStore.GetGroupById(Id); if (existingGroup is null) { throw new DomainException(ErrorMessages.GroupDoesNotExist); } var GroupOwner = _GroupStore.GetGroupOwner(existingGroup.Id); var Admin = _GroupStore.GetGroupMembers(Id) .FirstOrDefault(x => x.Type.Equals(GroupUserType.Admin) && x.UserId.Equals(CurrentUser.Id)); if (!CurrentUser.Id.Equals(GroupOwner.UserId) && Admin is null) { throw new ForbiddenException(ErrorMessages.ForbiddenAccess); } var GroupRequests = _GroupRequestStore.GetGroupRequestsOfGroup(existingGroup.Id); var GroupRequestViewModel = new GroupRequestsViewModel() { GroupOwner = GroupOwner.Username, OwnerIdentityUserID = GroupOwner.UserId, GroupID = existingGroup.Id, requests = new List <GroupRequestDTO>() }; foreach (var Request in GroupRequests) { var RequestUser = _GroupRequestStore.GetGroupRequestUser(Request.RequestUserId); var GroupRequestDTO = new GroupRequestDTO() { Id = Request.Id, Username = RequestUser.Username, RequestDate = Request.RequestDate, Pending = Request.Pending, Message = $"{RequestUser.Username} would like to join your group." }; GroupRequestViewModel.requests.Add(GroupRequestDTO); } return(View(GroupRequestViewModel)); } catch (DomainException ex) { _logger.LogError(ex.Message); if (ex.Message.Equals(ErrorMessages.GroupDoesNotExist)) { return(RedirectToAction(ActionName.NotFound, ControllerName.Accounts)); } return(RedirectToAction(ActionName.Login, ControllerName.Accounts)); } catch (ForbiddenException ex) { _logger.LogError(ex.Message); return(RedirectToAction(ActionName.NotAuthorized, ControllerName.Accounts)); } catch (Exception ex) { _logger.LogError(ex.Message); return(RedirectToAction(ActionName.ServerError, ControllerName.Accounts)); } }
public List <TeacherDTO> GetAllAvailableTeachers(GroupRequestDTO request) { return(_TeachersRepo.GetAllAvailableTeachers(request.GroupId)); }
public IActionResult GroupDetails(Guid Id) { try { var CurrentUser = _context.Users.Find(userManager.GetUserId(User)); if (CurrentUser is null) { throw new DomainException(ErrorMessages.NotSignedIn); } var existingAccount = _userStore.GetByIdentityUserId(CurrentUser.Id); if (existingAccount.AccountStatus.Equals(Status.Suspended)) { signInManager.SignOutAsync(); } var existingGroup = _GroupStore.GetGroupById(Id); if (existingGroup is null) { throw new DomainException(ErrorMessages.GroupDoesNotExist); } var groupMembers = _GroupStore.GetGroupMembers(existingGroup.Id); var Owner = _GroupStore.GetGroupOwner(existingGroup.Id); var Requests = _GroupRequestStore.GetGroupRequestsOfGroup(existingGroup.Id); var RequestDTOs = new List <GroupRequestDTO>(); foreach (var request in Requests) { var requestUser = _GroupRequestStore.GetGroupRequestUser(request.RequestUserId); var GroupRequestDTO = new GroupRequestDTO() { Username = requestUser.Username, Id = request.Id, GroupID = request.GroupId, RequestDate = request.RequestDate, RequestUserId = request.RequestUserId }; RequestDTOs.Add(GroupRequestDTO); } var CurrentUserAsRequestUser = RequestDTOs.FirstOrDefault(x => x.Username == CurrentUser.UserName); var CurrentUserAsMember = groupMembers.FirstOrDefault(x => x.Username == CurrentUser.UserName); var GroupAdmin = _GroupStore.GetGroupMembers(Id) .FirstOrDefault(x => x.Type.Equals(GroupUserType.Admin) && x.UserId.Equals(CurrentUser.Id)); var GroupDetailsDTO = new GroupDetailsDTO() { Id = existingGroup.Id, Name = existingGroup.Name, Description = existingGroup.Description, CreationDate = existingGroup.CreationDate, GroupOwner = Owner.Username, CurrentUsername = CurrentUser.UserName, GroupRequests = RequestDTOs, PendingRequest = (CurrentUserAsRequestUser != null) ? true : false, ExistingMember = (CurrentUserAsMember != null) ? true : false, Admin = (GroupAdmin != null) ? true : false }; foreach (var member in groupMembers) { var GroupMemberDTO = new GroupMemberDTO() { Id = member.Id, Username = member.Username, UserId = member.UserId, Type = member.Type }; GroupDetailsDTO.GroupMembers.Add(GroupMemberDTO); } return(View(GroupDetailsDTO)); } catch (DomainException ex) { _logger.LogError(ex.Message); if (ex.Message.Equals(ErrorMessages.NotSignedIn)) { return(RedirectToAction(ActionName.Login, ControllerName.Accounts)); } return(RedirectToAction(ActionName.NotFound, ControllerName.Accounts)); } catch (Exception ex) { _logger.LogError(ex.Message); return(RedirectToAction(ActionName.ServerError, ControllerName.Accounts)); } }
public List <ActivityDTO> GetAllGroupActivities(GroupRequestDTO request) { return(_ActivityRepo.GetAllGroupActivities(request.GroupId)); }
public GroupDTO GetGroupDetails(GroupRequestDTO request) { return(_GroupsRepo.GetGroupDetails(request.GroupId)); }
[Route("GetAllDocumentsByStudent")] // and groupid... public List <Document> GetAllDocumentsByStudent(GroupRequestDTO request) { return(_GroupsRepo.GetAllDocumentsByStudent(request.StudentId)); }
public bool UnAssignTeacher(GroupRequestDTO request) { return(_GroupsRepo.UnAssignTeacher(request.GroupId, request.TeacherId)); }
public bool UnEnrollStudent(GroupRequestDTO request) { return(_GroupsRepo.UnEnrollStudent(request.GroupId, request.StudentId)); }