public async Task <Result> CreateAsync(Action <UserCreateAction> action, CancellationToken cancellationToken = new CancellationToken()) { cancellationToken.RequestCanceled(LogInfo); var impl = new UserCreateActionImpl(); action(impl); DefinedUser definition = impl.Definition.Value; string user = impl.User.Value; if (string.IsNullOrWhiteSpace(user)) { throw new UserCredentialsMissingException("The username and/or password is missing."); } if (string.IsNullOrWhiteSpace(definition.Password) && string.IsNullOrWhiteSpace(definition.PasswordHash)) { throw new UserCredentialsMissingException("The username and/or password is missing."); } string url = $"api/users/{user}"; HttpResponseMessage response = await HttpPut(url, definition, cancellationToken); Result result = response.GetResponse(); LogInfo($"Sent request to RabbitMQ server to create user '{user}'"); return(result); }
public Task <Result> Create(Action <UserCreateAction> action, CancellationToken cancellationToken = default) { cancellationToken.RequestCanceled(); var impl = new UserCreateActionImpl(); action(impl); impl.Validate(); UserDefinition definition = impl.Definition.Value; Debug.Assert(definition != null); string url = $"api/users/{impl.User.Value}"; if (impl.Errors.Value.Any()) { return(Task.FromResult <Result>(new FaultedResult(impl.Errors.Value, new DebugInfoImpl(url, definition.ToJsonString(Deserializer.Options))))); } return(Put(url, definition, cancellationToken)); }
public async Task <Result> Create(Action <UserCreateAction> action, CancellationToken cancellationToken = default) { cancellationToken.RequestCanceled(); var impl = new UserCreateActionImpl(); action(impl); DefinedUser definition = impl.Definition.Value; Debug.Assert(definition != null); string user = impl.User.Value; var errors = new List <Error>(); if (string.IsNullOrWhiteSpace(user)) { errors.Add(new ErrorImpl("The username is missing.")); } if (string.IsNullOrWhiteSpace(definition.Password) && string.IsNullOrWhiteSpace(definition.PasswordHash)) { errors.Add(new ErrorImpl("The password/hash is missing.")); } if (errors.Any()) { return(new FaultedResult(errors)); } string url = $"api/users/{user}"; Result result = await Put(url, definition, cancellationToken); return(result); }