public async Task <int> Handle(CreateParticipantCommand request, CancellationToken cancellationToken) { var userId = await _identityService.GetUserByEmailAsync(request.Email); var participant = new Participant(userId, request.FirstName, request.LastName); participant.SetTitle(request.Title); if (request.ProjectId != null) { var project = await _context.Projects.FindAsync(request.ProjectId); if (project == null) { throw new NotFoundException($"{nameof(Project)} {request.ProjectId} not found"); } participant.AddProject(project); } await _context.Participants.AddAsync(participant, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(participant.Id); }