Example #1
0
        public async Task <IResult <IReadOnlyCollection <string> > > HandleAsync(GetUserGamesNamesQuery query)
        {
            var validationResult = await IsValidAsync(query);

            if (validationResult.HasFailed())
            {
                return(validationResult.Map <IReadOnlyCollection <string> >());
            }

            var userId = query.UserId ?? query.CurrentUserId;

            var user = await _dataContext.Users
                       .Include(x => x.Games)
                       .ThenInclude(x => x.Game)
                       .FirstAsync(x => x.Id == userId);

            return(user.Games
                   .Select(x => x.Game.Name)
                   .ToList()
                   .ToSuccessfulResult());
        }
Example #2
0
        private Task <IResult> IsValidAsync(GetUserGamesNamesQuery query)
        {
            _validator.ValidateUserIds(query.CurrentUserId, query.UserId);

            return(_validator.ValidateAsync());
        }