public async Task <IActionResult> Delete([FromRoute] string userNameOrId)
        {
            if (string.IsNullOrEmpty(ProjectId))
            {
                return(ErrorResult
                       .BadRequest($"Project Id provided in the url path is invalid.  Must be a valid GUID.", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            if (string.IsNullOrWhiteSpace(userNameOrId))
            {
                return(ErrorResult
                       .BadRequest($"The identifier '{userNameOrId}' provided in the url path is invalid.  Must be a valid email address or GUID.", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            var userId = await userService
                         .GetUserIdAsync(userNameOrId)
                         .ConfigureAwait(false);

            if (string.IsNullOrEmpty(userId))
            {
                return(ErrorResult
                       .NotFound($"The user '{userNameOrId}' could not be found.")
                       .ActionResult());
            }

            var user = await usersRepository
                       .GetAsync(userId)
                       .ConfigureAwait(false);

            if (user is null || !user.IsMember(ProjectId))
            {
                return(ErrorResult
                       .NotFound($"The specified User could not be found in this Project.")
                       .ActionResult());
            }

            if (user.IsOwner(ProjectId))
            {
                var otherOwners = await usersRepository
                                  .ListOwnersAsync(ProjectId)
                                  .AnyAsync(o => o.Id.Equals(userId, StringComparison.OrdinalIgnoreCase))
                                  .ConfigureAwait(false);

                if (!otherOwners)
                {
                    return(ErrorResult
                           .BadRequest($"Projects must have at least one Owner. To delete this user you must first add another Owner.", ResultErrorCode.ValidationError)
                           .ActionResult());
                }
            }

            var currentUserForCommand = await userService
                                        .CurrentUserAsync()
                                        .ConfigureAwait(false);

            var command = new OrchestratorProjectUserDeleteCommand(currentUserForCommand, user, ProjectId);

            return(await orchestrator
                   .InvokeAndReturnAccepted(command)
                   .ConfigureAwait(false));
        }
        public async Task <IActionResult> Delete([FromRoute] string userNameOrId)
        {
            if (!ProjectId.HasValue)
            {
                return(ErrorResult
                       .BadRequest($"Project Id provided in the url path is invalid.  Must be a valid GUID.", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            if (string.IsNullOrWhiteSpace(userNameOrId))
            {
                return(ErrorResult
                       .BadRequest($"The identifier '{userNameOrId}' provided in the url path is invalid.  Must be a valid email address or GUID.", ResultErrorCode.ValidationError)
                       .ActionResult());
            }

            var project = await projectsRepository
                          .GetAsync(ProjectId.Value)
                          .ConfigureAwait(false);

            if (project is null)
            {
                return(ErrorResult
                       .NotFound($"A Project with the ID '{ProjectId.Value}' could not be found in this TeamCloud Instance.")
                       .ActionResult());
            }

            if (!Guid.TryParse(userNameOrId, out var userId))
            {
                var idLookup = await userService
                               .GetUserIdAsync(userNameOrId)
                               .ConfigureAwait(false);

                if (!idLookup.HasValue || idLookup.Value == Guid.Empty)
                {
                    return(ErrorResult
                           .NotFound($"A User with the email '{userNameOrId}' could not be found.")
                           .ActionResult());
                }

                userId = idLookup.Value;
            }

            var user = project?.Users?.FirstOrDefault(u => u.Id == userId);

            if (user is null)
            {
                return(ErrorResult
                       .NotFound($"The specified User could not be found in this Project.")
                       .ActionResult());
            }

            var command = new OrchestratorProjectUserDeleteCommand(CurrentUser, user, ProjectId.Value);

            var commandResult = await orchestrator
                                .InvokeAsync(command)
                                .ConfigureAwait(false);

            if (commandResult.Links.TryGetValue("status", out var statusUrl))
            {
                return(StatusResult
                       .Accepted(commandResult.CommandId.ToString(), statusUrl, commandResult.RuntimeStatus.ToString(), commandResult.CustomStatus)
                       .ActionResult());
            }

            throw new Exception("This shoudn't happen, but we need to decide to do when it does.");
        }