コード例 #1
0
        public async Task <IdeaCommentDto> CreateComment(string ideaId, [FromBody] IdeaCommentDto comment)
        {
            comment.IdeaId  = ideaId;
            comment.OwnerId = _userIdentityProvider.GetUserId();
            var createdComment = await _ideaCommentService.CreateAsync(comment);

            return(await _ideaCommentService.GetCommentAsync(createdComment.Id));
        }
コード例 #2
0
        protected override async Task Validate(FilterContext <AddTaskItemCommand> context)
        {
            var taskBoard = await _repository.GetOneAsync <TaskBoard>(context.Message.BoardId);

            if (taskBoard == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid board");
            }

            var team = await _repository.GetOneAsync <Team>(taskBoard.TeamId);

            if (team == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid team");
            }

            if (!team.Members.Any(i => i.MemberUserId == _userIdentityProvider.GetUserId()))
            {
                throw new LogicalException(ErrorCategory.UnAuthorized);
            }

            var state = await _repository.GetOneAsync <TaskItemState>(context.Message.Item.StateId);

            if (state == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid task state");
            }

            var type = await _repository.GetOneAsync <TaskItemState>(context.Message.Item.TaskTypeId);

            if (type == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid task type");
            }
        }
コード例 #3
0
        protected override async Task Validate(FilterContext <DeleteTaskItemCommand> context)
        {
            var task = await _repository.GetOneAsync <TaskItem>(context.Message.TaskItemId);

            if (task == null)
            {
                throw new LogicalException(ErrorCategory.NotFound, "task not found");
            }

            var taskBoard = await _repository.GetOneAsync <TaskBoard>(task.TaskBoardId);

            if (taskBoard == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid board");
            }

            var team = await _repository.GetOneAsync <Team>(taskBoard.TeamId);

            if (team == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid team");
            }

            if (!team.Members.Any(i => i.MemberUserId == _userIdentityProvider.GetUserId()))
            {
                throw new LogicalException(ErrorCategory.UnAuthorized);
            }
        }
コード例 #4
0
ファイル: IdeaLogic.cs プロジェクト: appsflare/pro-ideas-v2
        public Task Handle(UpdateIdeaCommand message)
        {
            var ideaTobeUpdated = _dataMapper.Map <Idea>(message.Idea);

            var existing = _repository.GetOne <Idea>(message.Idea.Id);


            existing.Title              = ideaTobeUpdated.Title;
            existing.Description        = ideaTobeUpdated.Description;
            existing.IsFundingRequired  = ideaTobeUpdated.IsFundingRequired;
            existing.FundingRequirement = ideaTobeUpdated.FundingRequirement;

            existing.ModifiedAt     = DateTime.UtcNow;
            existing.LastModifiedBy = _userIdentityProvider.GetUserId();

            var result = _repository.Update(existing);

            return(_bus.RaiseEvent(new IdeaUpdatedEvent(_dataMapper.Map <IdeaDto>(result))));
        }
コード例 #5
0
        public async Task Handle(IdeaLikeChangedEvent message)
        {
            var idea = await GetIdea(message.IdeaId);

            if (idea == null)
            {
                return;
            }

            await _repository.AddAsync(new Activity
            {
                Type        = Activity.IDEAS_VOTES,
                Body        = string.Empty,
                OwnerId     = _userIdentityProvider.GetUserId(),
                CreatedAt   = DateTime.UtcNow,
                ItemOwnerId = message.UserId,
                IdeaId      = message.IdeaId,
                IdeaOwnerId = idea.OwnerId,
                ItemDetails = new ActivityItemDetails
                {
                    IsUpVote = message.Like
                }
            });
        }
コード例 #6
0
        protected override Task Validate(FilterContext <UnpublishIdeaCommand> context)
        {
            if (!context.Message.IsValid())
            {
                throw new ArgumentException(nameof(context.Message));
            }

            var idea = _repository.GetOne <Idea>(context.Message.IdeaId);

            if (idea.OwnerId != _userIdentityProvider.GetUserId())
            {
                throw new UnauthorizedAccessException();
            }

            return(Task.CompletedTask);
        }
コード例 #7
0
        public async Task Handle(AddTaskItemCommand message)
        {
            var task = _dataMapper.Map <TaskItem>(message.Item);

            task.CreatedAt = DateTime.UtcNow;
            task.CreatedBy = _userIdentityProvider.GetUserId();


            var addedTask = await _repository.AddAsync(task);

            message.SetTaskItemId(task.Id);

            await _bus.RaiseEvent(new TaskItemAddedEvent(_dataMapper.Map <TaskItemDto>(addedTask)));
        }
        protected override Task Validate(FilterContext <DeleteIdeaCommentCommand> context)
        {
            if (!context.Message.IsValid())
            {
                throw new ArgumentException(nameof(context.Message));
            }

            var comment = _repository.GetOne <IdeaComment>(context.Message.CommentId);

            if (comment == null)
            {
                throw new InvalidOperationException("invalid comment");
            }

            if (comment.OwnerId != _userIdentityProvider.GetUserId())
            {
                throw new UnauthorizedAccessException();
            }

            return(Task.CompletedTask);
        }
コード例 #9
0
        protected override async Task Validate(FilterContext <CreateTaskBoardCommand> context)
        {
            var idea = await _repository.GetOneAsync <Idea>(context.Message.IdeaId);

            if (idea == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid idea");
            }

            var team = await _repository.GetOneAsync <Team>(context.Message.TaskBoard.TeamId);

            if (team == null)
            {
                throw new LogicalException(ErrorCategory.InvalidInput, "Invalid team");
            }

            if (!team.Members.Any(i => i.MemberUserId == _userIdentityProvider.GetUserId()))
            {
                throw new LogicalException(ErrorCategory.UnAuthorized);
            }
        }
コード例 #10
0
 public Task <IEnumerable <IdeaDto> > FilterMyIdeas(string keyword, int pageSize = 10, int page = 1)
 {
     return(_ideaService.GetUserIdeasAsync(_userIdentityProvider.GetUserId(), pageSize, page, keyword));
 }
コード例 #11
0
        public async Task <IActionResult> MyIdeas()
        {
            var ideas = await _ideaService.GetUserIdeasAsync(_userIdentityProvider.GetUserId(), 10, 1, string.Empty);

            return(View(IndexIdeasViewModel.MapFrom(ideas)));
        }
コード例 #12
0
ファイル: TodoContext.cs プロジェクト: mgiuseppe/TheTodoList
 public TodoContext(DbContextOptions <TodoContext> options, IUserIdentityProvider userIdentityProvider)
     : base(options)
 {
     this.userId = userIdentityProvider.GetUserId();
 }