Ejemplo n.º 1
0
            public override async Task <ProjectAccess> Handle(Request request, CancellationToken cancellationToken)
            {
                var project = _projects.SingleOrDefault(_ => _.Id == request.ProjectId);

                if (project == null)
                {
                    Logger.LogInformation("Project {ProjectId} not found", request.ProjectId);
                    throw new ProjectNotFoundException(request.ProjectId);
                }

                var user = await _userSearchService.SearchAsync(request.Username);

                if (user == null)
                {
                    Logger.LogInformation("User {Username} not found", request.Username);
                    throw new UserNotFoundException(request.Username);
                }

                using CancellationTokenSource cts = CreateCancellationTokenSource(cancellationToken);

                var access = await _userManagementService.AddUserToProjectAsync(user, project, cts.Token);

                return(new ProjectAccess
                {
                    Id = project.Id,
                    Name = project.Name,
                    Users = new List <UserAccess>
                    {
                        new UserAccess {
                            Username = user.UserName, Access = access
                        }
                    }
                });
            }