Exemplo n.º 1
0
        public async Task<IActionResult> GetAllByProfileIdAsync(Guid profileId, string nameFilter = null, int pageNumber = 1, int pageSize = 20)
        {
            ProfileAccessResult canAccessDiets = await _profileDomainService.CanAccessProfileData(_currentProfileId, profileId);

            if (canAccessDiets == ProfileAccessResult.CanAccess)
            {
                IEnumerable<DietListReadModel> diets = await _readModelRepository.GetDietListAsync(profileId, nameFilter, pageNumber, pageSize);
                return CreateResponse(diets);
            }
            else if (canAccessDiets == ProfileAccessResult.Forbidden) return Forbid();

            return NotFound();
        }
Exemplo n.º 2
0
        public async Task <CommandResult> Handle(ReplyCommentCommand request, CancellationToken cancellationToken)
        {
            Post post = await _postRepository.GetByIdAsync(request.PostId);

            ProfileAccessResult accessResult = await _profileDomainService.CanAccessProfileData(_currentProfileId, post.ProfileId);

            if (accessResult != ProfileAccessResult.CanAccess)
            {
                return(FailureDueToPostNotFound());
            }

            Comment comment = await _commentRepository.GetByIdAsync(request.CommentId);

            if (comment == null)
            {
                return(FailureDueToCommentNotFound());
            }

            comment.Reply(
                _currentProfileId,
                request.Body
                );

            await _commentRepository.UpdateAsync(comment);

            return(await CommitAndPublishDefaultAsync());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetAllByProfileIdAsync(Guid profileId, string titleFilter = null, int pageNumber = 1, int pageSize = 20)
        {
            ProfileAccessResult canAccessMeasures = await _profileDomainService.CanAccessProfileData(_currentProfileId, profileId);

            if (canAccessMeasures == ProfileAccessResult.CanAccess)
            {
                IEnumerable <MeasureListReadModel> measures = await _measureReadModelRepository.GetMeasureListAsync(profileId, titleFilter, pageNumber, pageSize);

                return(CreateResponse(measures));
            }
            else if (canAccessMeasures == ProfileAccessResult.Forbidden)
            {
                return(Forbid());
            }

            return(NotFound());
        }
Exemplo n.º 4
0
        private async Task <bool> CanModifyPost(Post post)
        {
            if (post == null)
            {
                return(false);
            }

            ProfileAccessResult accessResult = await _profileDomainService.CanAccessProfileData(_currentProfileId, post.ProfileId);

            return(accessResult == ProfileAccessResult.CanAccess);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetProfileFriendsAsync(Guid profileId, string nameFilter = null)
        {
            ProfileAccessResult canAccessGoals = await _profileDomainService.CanAccessProfileData(_currentProfileId, profileId);

            if (canAccessGoals == ProfileAccessResult.CanAccess)
            {
                IEnumerable <ProfileFriendReadModel> friends = await _readModelRepository.GetProfileFriendsAsync(profileId, nameFilter);

                return(CreateResponse(friends));
            }
            else if (canAccessGoals == ProfileAccessResult.Forbidden)
            {
                return(Forbid());
            }

            return(NotFound());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> GetMealSummaryAsync(Guid id)
        {
            MealSummaryReadModel meal = await _readModelRepository.GetMealSummaryAsync(id);

            if (meal != null)
            {
                ProfileAccessResult canAccessMeal = await _profileDomainService.CanAccessProfileData(_currentProfileId, meal.ProfileId);

                if (canAccessMeal == ProfileAccessResult.CanAccess)
                {
                    return(CreateResponse(meal));
                }
                if (canAccessMeal == ProfileAccessResult.Forbidden)
                {
                    return(Forbid());
                }
            }

            return(NotFound());
        }