public async Task <IActionResult> CreateClient([FromBody] CreateClientModel request) { var validated = await this.createValidator.ValidateAsync(request); if (!validated.IsValid) { return(this.Error <ClientModel>(new InvalidObjectException("Invalid client.", validated))); } if (await this.getClientById.GetResult(NewGetByIdParam(request.Id))) { return(this.Error <ClientModel>(new AlreadyExistsException("Client already exists."))); } Option <Client> entity = request; var @try = await this.upsertClient.Execute(NewUpsertParam(entity)); return(@try.Match( this.Error <ClientModel>, _ => this.Created(entity.Get().Id, Success(NewClientModel(entity.Get()))))); }