Beispiel #1
0
        public async Task <IEnumerable <InvitationDto> > Handle(GetUserInvitationsQuery getUserInvitationsQuery, CancellationToken cancellationToken)
        {
            _authorizationService.AuthorizeAccessOrThrow(_httpContextAccessor.HttpContext, getUserInvitationsQuery.UserId);
            var invitations = await _invitationRepository.GetUsersInvitationsAsync(getUserInvitationsQuery.UserId);

            var mappedInvitations = invitations.Select(x => _mapper.Map <InvitationDto>(x)).ToList();

            return(mappedInvitations);
        }
        public async Task <string> Handle(DeleteUserCommand request, CancellationToken cancellationToken)
        {
            _authorizationService.AuthorizeAccessOrThrow(_httpContextAccessor.HttpContext, request.Id);
            await _userRepository.DeleteUserAsync(request.Id);

            await UpdateGroupsAsync(request.Id);

            return(request.Id);
        }
        public async Task <UserDto> Handle(GetUserQuery getUserQuery, CancellationToken cancellationToken)
        {
            _authorizationService.AuthorizeAccessOrThrow(_httpContextAccessor.HttpContext, getUserQuery.Id);
            var user = await _userRepository.GetUserByIdAsync(getUserQuery.Id);

            var mappedUser = _mapper.Map <UserDO, UserDto>(user);

            mappedUser.MoviePreference.Movies = await GetMovies(mappedUser.MoviePreference.Ratings);

            return(mappedUser);
        }
        public async Task <string> Handle(RespondToInvitationCommand request, CancellationToken cancellationToken)
        {
            var invitation = await _invitationRepository.GetInvitationByIdAsync(request.InvitationId);

            _authorizationService.AuthorizeAccessOrThrow(_httpContextAccessor.HttpContext, invitation.UserId);
            if (request.Decision)
            {
                await UpdateGroupAsync(invitation);
                await UpdateUserAsync(invitation);
            }
            await _invitationRepository.DeleteInvitationAsync(invitation.Id);

            return(invitation.Id);
        }
Beispiel #5
0
        public async Task <string> Handle(RateMovieCommand request, CancellationToken cancellationToken)
        {
            _authorizationService.AuthorizeAccessOrThrow(_httpContextAccessor.HttpContext, request.UserID);
            var user = await _userRepository.GetUserByIdAsync(request.UserID);

            if (user.MoviePreference.Ratings.ContainsKey(request.MovieID))
            {
                user.MoviePreference.Ratings[request.MovieID] = request.Rating;
            }
            else
            {
                user.MoviePreference.Ratings.Add(request.MovieID, request.Rating);
            }
            await _userRepository.UpdateUserAsync(user);

            return(request.MovieID);
        }
        public async Task <string> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
        {
            _authorizationService.AuthorizeAccessOrThrow(_httpContextAccessor.HttpContext, request.Id);
            var user = await _userRepository.GetUserByIdAsync(request.Id);

            var changes = _mapper.Map <UserDO>(request);
            var updated = new UserDO
            {
                ID              = user.ID,
                Login           = user.Login,
                Salt            = user.Salt,
                Password        = user.Password,
                Name            = String.IsNullOrEmpty(changes.Name) ? user.Name : changes.Name,
                AvailableDates  = changes.AvailableDates ?? user.AvailableDates,
                GroupIDs        = changes.GroupIDs ?? user.GroupIDs,
                MealPreference  = changes.MealPreference != null ? changes.MealPreference : user.MealPreference,
                MoviePreference = changes.MoviePreference != null ? changes.MoviePreference : user.MoviePreference
            };
            await _userRepository.UpdateUserAsync(updated);

            await UpdateGroupsAsync(request.Id, request.GroupIDs);

            return(request.Id);
        }