Beispiel #1
0
        public async Task AddPhotosAsync(Guid remarkId, string userId, params File[] photos)
        {
            if (photos == null || !photos.Any())
            {
                throw new ServiceException(OperationCodes.NoFiles,
                                           $"There are no photos to be added to the remark with id: '{remarkId}'.");
            }

            var user = await _userRepository.GetOrFailAsync(userId);

            Logger.Debug($"Adding {photos.Count()} photos to remark with id: '{remarkId}'.");
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            if (remark.Photos.GroupBy(x => x.Size).Count() + photos.Count() > _settings.PhotosLimit)
            {
                throw new ServiceException(OperationCodes.TooManyFiles,
                                           $"There are too many photos ({photos.Count()}) to be added to the remark with id: '{remarkId}'.");
            }
            var tasks = new List <Task>();

            foreach (var photo in photos)
            {
                var task = UploadImagesWithDifferentSizesAsync(remark, RemarkUser.Create(user), photo);
                tasks.Add(task);
            }
            await Task.WhenAll(tasks);

            await _remarkRepository.UpdateAsync(remark);

            Logger.Debug($"Added {photos.Count()} photos to remark with id: '{remarkId}'.");
        }
        private async Task <Report> ReportActivityAsync(Guid remarkId, Guid?activityId, string userId)
        {
            if (activityId == null || activityId == Guid.Empty)
            {
                throw new ServiceException(OperationCodes.EmptyReportResource,
                                           $"Empty report resource for activity type sent by user: '******' "
                                           + $"for remark: '{remarkId}'.");
            }
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            var acitivity = remark.GetStateOrFail(activityId.Value);

            return(new Report(remarkId, activityId, "activity", userId));
        }
        public async Task ValidateAsync(Guid remarkId, string userId)
        {
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            var latestState = remark.States.OrderBy(x => x.CreatedAt)
                              .LastOrDefault(x => x.User.UserId == userId);

            Validate(latestState, OperationCodes.CannotSetStateTooOften,
                     $"Can not process remark too often. Remark: '{remarkId}', user: '******'.");
        }
Beispiel #4
0
        public async Task ValidateAsync(Guid remarkId, string userId)
        {
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            var latestComment = remark.Comments.OrderBy(x => x.CreatedAt)
                                .LastOrDefault(x => x.User.UserId == userId);

            Validate(latestComment, OperationCodes.CannotAddCommentTooOften,
                     $"Can not add remark comment too often. Remark: '{remarkId}', user: '******'.");
        }
        public async Task ValidateRemoveStateAccessOrFailAsync(Guid remarkId, Guid stateId, string userId)
        {
            var user = await _userRepository.GetOrFailAsync(userId);

            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            var state = remark.GetState(stateId);

            if (state.HasNoValue)
            {
                throw new ServiceException(OperationCodes.StateNotFound, "Cannot find state." +
                                           $" remarkId: {remarkId}, stateId: {stateId}");
            }

            if (state.Value.User.UserId != user.UserId)
            {
                throw new ServiceException(OperationCodes.UserNotAllowedToRemoveState,
                                           $"User: {userId} is not allowed to remove state: {stateId}");
            }
        }
Beispiel #6
0
        public async Task ValidateIfRemarkCommentCanBeDeletedOrFailAsync(Guid groupId,
                                                                         string userId, Guid remarkId, Guid commentId)
        {
            var user = await _userRepository.GetOrFailAsync(userId);

            ValidateUserOrFail(user);
            var group = await _groupRepository.GetOrFailAsync(groupId);

            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            var comment    = remark.GetCommentOrFail(commentId);
            var memberRole = GetActiveMemberRoleOrFail(group, user);

            ValidateRemarkMemberCriteriaOrFail(null, memberRole, "remark_comment_delete");
        }
        public async Task ValidateEditorAccessOrFailAsync(Guid remarkId, string userId)
        {
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            var user = await _userRepository.GetOrFailAsync(userId);

            if (user.Role == "moderator" || user.Role == "administrator" || user.Role == "owner")
            {
                return;
            }
            if (remark.Author.UserId != user.UserId)
            {
                throw new ServiceException(OperationCodes.UserNotAllowedToModifyRemark,
                                           $"User with id: '{userId}' is not allowed " +
                                           $"to modify the remark with id: '{remarkId}'.");
            }
        }
        public async Task <Maybe <Comment> > GetAsync(Guid remarkId, Guid commentId)
        {
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            return(remark.GetComment(commentId));
        }
Beispiel #9
0
        public async Task <Maybe <Participant> > GetParticipantAsync(Guid remarkId, string userId)
        {
            var remark = await _remarkRepository.GetOrFailAsync(remarkId);

            return(remark.GetParticipant(userId));
        }