public MemberRequest updateMemberRequest(String key, long receiverUserId)
      throws PortalException, SystemException {

    MemberRequest memberRequest = memberRequestPersistence.findByKey(key);

    validate(memberRequest, 0);

    memberRequest.setModifiedDate(new Date());
    memberRequest.setReceiverUserId(receiverUserId);

    memberRequestPersistence.update(memberRequest, false);

    return memberRequest;
  }
  public MemberRequest addMemberRequest(
      long userId,
      long groupId,
      long receiverUserId,
      String receiverEmailAddress,
      long invitedRoleId,
      long invitedTeamId,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Member request

    User user = userLocalService.getUserById(userId);

    Date now = new Date();

    long memberRequestId = counterLocalService.increment();

    MemberRequest memberRequest = memberRequestPersistence.create(memberRequestId);

    memberRequest.setGroupId(groupId);
    memberRequest.setCompanyId(user.getCompanyId());
    memberRequest.setUserId(userId);
    memberRequest.setUserName(user.getFullName());
    memberRequest.setCreateDate(now);
    memberRequest.setModifiedDate(now);
    memberRequest.setKey(PortalUUIDUtil.generate());
    memberRequest.setReceiverUserId(receiverUserId);
    memberRequest.setInvitedRoleId(invitedRoleId);
    memberRequest.setInvitedTeamId(invitedTeamId);
    memberRequest.setStatus(InviteMembersConstants.STATUS_PENDING);

    memberRequestPersistence.update(memberRequest, false);

    // Email

    try {
      sendEmail(receiverEmailAddress, memberRequest, serviceContext);
    } catch (Exception e) {
      throw new SystemException(e);
    }

    // Notifications

    sendNotificationEvent(memberRequest);

    return memberRequest;
  }