Beispiel #1
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var currentUser = await _authenticatedUserService.GetAuthenticatedUser();

                currentUser.RemoveFriend(request.FriendId);

                await _userManager.UpdateAsync(currentUser);

                return(Unit.Value);
            }
Beispiel #2
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var user = await _authenticatedUserService.GetAuthenticatedUser();

                user.AddGameToCollection(request.GameId, request.SkillLevel, request.WillingToPlayWith,
                                         request.OwnsAllComponents, request.GameMaster, request.ActivelyLooking);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Beispiel #3
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var user = await _authenticatedUserService.GetAuthenticatedUser();

                var queue = await _context
                            .GroupFinder
                            .SingleOrDefaultAsync(x => x.QueueType == request.QueueType,
                                                  cancellationToken : cancellationToken);

                queue.AddToQueue(user);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Beispiel #4
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var currentUser = await _authenticatedUserService.GetAuthenticatedUser();

                if (currentUser.AddFriend(request.FriendId))
                {
                    var friend = await _userManager.FindByIdAsync(request.FriendId);

                    _smtpEmailSender.SendEmail($"{currentUser.UserName} has sent you a friend request",
                                               $"{currentUser.UserName} has sent you a friend request, login to accept or reject it",
                                               friend.Email);
                    await _userManager.UpdateAsync(currentUser);
                }

                return(Unit.Value);
            }
Beispiel #5
0
            public async Task <List <UserGroupListDto> > Handle(Request request, CancellationToken cancellationToken)
            {
                var user = await _authenticatedUserService.GetAuthenticatedUser();

                var groups = await _context.Groups
                             .Where(x => x.Members.Select(x => x.UserId)
                                    .Contains(user.Id))
                             .Select(x => new UserGroupListDto()
                {
                    GroupName    = x.Name,
                    Description  = x.Description,
                    MemberIds    = x.Members.Select(x => x.UserId).ToList(),
                    PrivacyLevel = x.PrivacyLevel
                })
                             .ToListAsync(cancellationToken: cancellationToken);

                return(groups);
            }
Beispiel #6
0
            public async Task <int> Handle(Request request, CancellationToken cancellationToken)
            {
                var currentUser = await _authenticatedUserService.GetAuthenticatedUser();

                var group = _context.Groups.SingleOrDefault(x => x.Name == request.GroupName);

                if (group != null)
                {
                    throw new EntityAlreadyExistsException("group", "a group with this name already exists");
                }

                group = new Group(request.GroupName, request.Description,
                                  Enum.Parse <GroupPrivacyLevel>(request.PrivacyLevel, true),
                                  currentUser, request.MinPlayers, request.MaxPlayers);

                _context.Groups.Add(group);

                await _context.SaveChangesAsync(cancellationToken);

                return(group.Id);
            }
Beispiel #7
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var currentUser = await _authenticatedUserService.GetAuthenticatedUser();

                var group = await _context.Groups
                            .Include(x => x.Members)
                            .Where(x => x.Id == request.GroupId)
                            .SingleOrDefaultAsync(cancellationToken: cancellationToken);

                if (group == null)
                {
                    throw new JoinGroupException("unable to join group as it doesn't exist");
                }

                group.JoinGroup(currentUser);

                if (await _context.SaveChangesAsync(cancellationToken) <= 0)
                {
                    _logger.LogCritical($"Failed to join group for {currentUser.Id} and group {group.Id}");
                    throw new JoinGroupException("something went wrong, looks like this group might be setup incorrectly, we've logged the issue and will fix it asap");
                }

                return(Unit.Value);
            }