public async Task <CompetitionUserResponse> AddInvite(Guid differentUserId, Guid competitionId)
        {
            var existingInvitation = await _invitationRepo.Get(differentUserId, competitionId);

            existingInvitation.EnsureDoesNotExist();

            var participant = await _participantRepo.Get(differentUserId, competitionId);

            participant.EnsureDoesNotExist("User is already in competition.");

            var user = await _userRepo.Get(differentUserId);

            user.EnsureExists("User not found.");

            var invitation = new Invitation(differentUserId, competitionId);

            _invitationRepo.Create(invitation);
            await _invitationRepo.Save();

            return(new CompetitionUserResponse(user));
        }
Пример #2
0
        public async Task <ParticipantResponse> AddParticipantToCompetitionAsUser(Guid userId, Guid competitionId)
        {
            var invitation = await _invitationRepo.Get(userId, competitionId);

            invitation.EnsureExists("User has not been invited to join competition.");

            var participant = new Participant(userId, competitionId);

            _invitationRepo.Delete(invitation);
            _participantRepo.Create(participant);
            await _participantRepo.Save();

            return(new ParticipantResponse(participant));
        }