36 lines
No EOL
1.1 KiB
C#
36 lines
No EOL
1.1 KiB
C#
using Insight.Database;
|
|
using PlanTempus.Core.Sql;
|
|
|
|
namespace PlanTempus.Components.Organizations.Create
|
|
{
|
|
public class CreateOrganizationHandler(IDatabaseOperations databaseOperations)
|
|
{
|
|
public async Task<CreateOrganizationResult> Handle(CreateOrganizationCommand command)
|
|
{
|
|
using var db = databaseOperations.CreateScope(nameof(CreateOrganizationHandler));
|
|
|
|
try
|
|
{
|
|
var sql = @"INSERT INTO organizations (connection_string, created_by)
|
|
VALUES (@ConnectionString, @CreatedBy)
|
|
RETURNING id, created_at";
|
|
|
|
|
|
var data = await db.Connection.QuerySqlAsync<CreateOrganizationResult>(sql, new
|
|
{
|
|
ConnectionString = command.ConnectionString,
|
|
CreatedBy = command.CreatedById
|
|
});
|
|
|
|
db.Success();
|
|
|
|
return data.First();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Error(ex);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
} |