public async Task UpsertClientAsync(ClientInputModel inputModel) { try { ClientValidations.Validate(inputModel); var clientData = inputModel.ToData(Cryptography); if (string.IsNullOrWhiteSpace(clientData.Id)) { await ClientDataAccess.InsertAsync(clientData); } else { await ClientDataAccess.ReplaceAsync(clientData, (data) => data.Id == clientData.Id); } } catch (MongoWriteException ex) { ex.ThrowIfDuplicateKey(nameof(inputModel.ClientId), $"O id do client '{inputModel.ClientId}' já existe"); throw ex; } }