public async Task <IEnumerable <ProjectDto> > Handle(GetAllProjectsQuery query, CancellationToken cancellationToken) { var specification = new ProjectSpecification(); var projects = await _projectRepository.GetAllAsync(specification); var mappedProjects = projects.Select(_mapperService.MapProjectToProjectDto).ToArray(); return(mappedProjects); }
public async Task Handle(DeleteProjectCommand command, CancellationToken cancellationToken) { var projectSpecification = new ProjectSpecification(command.Id); var project = await _projectRepository.GetSingleOrDefaultAsync(projectSpecification); Check.NotNull(project, nameof(project)); if (project.Owner.Id != _currentUserService.UserId) { throw new UserException("Sorry You Cant not delete this project"); } _projectRepository.Delete(project); await _unitOfWork.SaveChangesAsync(); }
public async Task <ProjectDto> Handle(GetProjectByIdQuery query, CancellationToken cancellationToken) { var specification = new ProjectSpecification(query.Id); var project = await _projectRepository.GetSingleOrDefaultAsync(specification); return(new ProjectDto { Name = project.Name, Key = project.Key, Issues = project.Issues.Select(_mapperService.MapIssueToIssueDto), Owner = _mapperService.MapUserToUserDto(project.Owner), Participants = project.Participants.Select(_mapperService.MapUserToUserDto), Id = project.Id }); }
public async Task Handle(UpdateProjectParticipantsCommand command, CancellationToken cancellationToken) { var specification = new UserSpecification(command.Participants); var users = await _useRepository.GetAllAsync(specification); var projectSpecification = new ProjectSpecification(command.Id); var project = await _projectRepository.GetSingleOrDefaultAsync(projectSpecification); var existingParticipant = project.Participants.Select(user => user).ToArray(); var newParticipants = users.Except(existingParticipant).ToArray(); var deletedParticipants = existingParticipant.Except(users).ToArray(); var participants = existingParticipant.Except(deletedParticipants).Concat(newParticipants).ToArray(); project.UpdateProjectParticipants(participants); await _unitOfWork.SaveChangesAsync(); }
public async Task Handle(CreateIssueCommand command, CancellationToken cancellationToken) { var projectSpecification = new ProjectSpecification(command.ProjectId); var project = await _projectRepository.GetSingleOrDefaultAsync(projectSpecification); Check.NotNull(project, nameof(project)); string issueId = (project.Issues.Count() + 1).ToString() + project.Key.ToUpper(); var issue = new Domain.Entities.IssueAggregate.Issue( issueId, command.Type, command.Title, command.Description, _currentUserService.User, project, command.Status); _issueRepository.Add(issue); await _unitOfWork.SaveChangesAsync(); }