Пример #1
0
        /// <summary>
        /// Invite user to a group
        /// </summary>
        /// <param name="emailAddress">the email of the user to be invited</param>
        /// <param name="groupID">The group where the user is invited for</param>
        /// <param name="sendingUserID">The id of the user that is sending the invitation</param>
        /// <returns>true if the invitation is send, false otherwise</returns>
        public bool InviteUserToGroup(int sendingUserID, string emailAddress, int groupID)
        {
            User  recievingUser = _unitOfWork.UserRepository.GetUser(emailAddress);
            User  sendingUser   = _unitOfWork.UserRepository.GetUser(sendingUserID);
            Group group         = RetrieveGroupById(groupID, sendingUserID);

            if (recievingUser == default(User) || sendingUser == default(User) || group == default(Group) || Equals(recievingUser.ID, sendingUser.ID))
            {
                _logger.LogError($"Couldn't send invation to {emailAddress} from {sendingUserID} for group {groupID}: Incomplete or Incorrect data");
                throw new InvalidInputException("Couldn't send invation");
            }

            try
            {
                EmailDTO emailData = _emailHandler.CreateInviteEmail(recievingUser, sendingUser, group);
                _emailHandler.SendInviteEmail(emailData);
            }
            catch (Exception exception)
            {
                _logger.LogError($"Could not send invite email to {emailAddress}");
                throw exception;
            }

            return(true);
        }