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)); }
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"); } }
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); } }
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)))); }
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 } }); }
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); }
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); }
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); } }
public Task <IEnumerable <IdeaDto> > FilterMyIdeas(string keyword, int pageSize = 10, int page = 1) { return(_ideaService.GetUserIdeasAsync(_userIdentityProvider.GetUserId(), pageSize, page, keyword)); }
public async Task <IActionResult> MyIdeas() { var ideas = await _ideaService.GetUserIdeasAsync(_userIdentityProvider.GetUserId(), 10, 1, string.Empty); return(View(IndexIdeasViewModel.MapFrom(ideas))); }
public TodoContext(DbContextOptions <TodoContext> options, IUserIdentityProvider userIdentityProvider) : base(options) { this.userId = userIdentityProvider.GetUserId(); }