Exemplo n.º 1
0
        private async Task AcceptInvitationAsync(ClubInvitation invitation, Guid userId)
        {
            var membership = new ClubMembership {
                UserId = userId, ClubId = invitation.ClubId
            };
            await _context.AddAsync(membership);

            _context.Remove(invitation);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task AddInvitation(Guid clubId, string userName)
        {
            var user = await _userService.GetLoggedInUserAsync();

            if (await isAdmin(user.UserId, clubId))
            {
                var invitedUser = await _userService.GetUserByUserNameAsync(userName);

                if (await isMember(clubId, invitedUser.UserId))
                {
                    throw new InvalidOperationException("User is already a member of this club");
                }
                var invitation = new ClubInvitation {
                    ClubId = clubId, UserId = invitedUser.UserId
                };
                await _context.AddAsync(invitation);

                await _context.SaveChangesAsync();
            }
            else
            {
                throw new UnauthorizedException($"Not authorized to invite user to club with id, {clubId}");
            }
        }
Exemplo n.º 3
0
 private async Task RejectInvitationAsync(ClubInvitation invitation)
 {
     _context.Remove(invitation);
     await _context.SaveChangesAsync();
 }