public async Task <OrganizationUserInvitationGetRp> GetInvitationById(Guid invitationId) { var entity = await _organizationUserInvitationRepository.GetOrganizationUserInvitationById(invitationId); OrganizationUserInvitationGetRp invitation = null; if (entity != null) { invitation = new OrganizationUserInvitationGetRp() { InvitationId = entity.OrganizationUserInvitationId, UserEmail = entity.UserEmail, Role = entity.Role, InvitationStatus = entity.InvitationStatus, AcceptedDate = entity.AcceptedDate, CreationDate = entity.CreationDate }; } return(invitation); }
public async Task AcceptInvitation(Guid organizationId, Guid invitationId) { string loggedUserId = _identityService.GetUserId(); string loggedUserEmail = _identityService.GetUserEmail(); User user = await _userRepository.GetUser(loggedUserId); OrganizationUserInvitation organizationUserInvitation = await _organizationUserInvitationRepository.GetOrganizationUserInvitationById(invitationId); if (organizationUserInvitation == null) { await _domainManagerService.AddNotFound($"The invitation with id {invitationId} does not exists."); return; } if (!loggedUserEmail.Equals(organizationUserInvitation.UserEmail, StringComparison.InvariantCultureIgnoreCase)) { await _domainManagerService.AddForbidden($"You are not authorized to accept this invitation."); return; } if (organizationUserInvitation.InvitationStatus != UserInvitationStatus.Pending) { await _domainManagerService.AddConflict($"The invitation with id {invitationId} cannot be accepted. Only invitations in status pending can be accepted."); return; } organizationUserInvitation.Accept(); //Grant User Access organizationUserInvitation.Organization.GrantUserAccess(loggedUserId, organizationUserInvitation.Role); await _organizationUserInvitationRepository.SaveChanges(); }