54 lines
No EOL
1.6 KiB
C#
54 lines
No EOL
1.6 KiB
C#
using Insight.Database;
|
|
using PlanTempus.Core.Sql;
|
|
|
|
namespace PlanTempus.Components.Organizations.Create
|
|
{
|
|
public class CreateOrganizationHandler
|
|
{
|
|
private readonly IDatabaseOperations _databaseOperations;
|
|
|
|
public CreateOrganizationHandler(IDatabaseOperations databaseOperations)
|
|
{
|
|
_databaseOperations = databaseOperations;
|
|
}
|
|
|
|
public async Task<CreateOrganizationResponse> Handle(CreateOrganizationCommand command)
|
|
{
|
|
using var db = _databaseOperations.CreateScope(nameof(CreateOrganizationHandler));
|
|
try
|
|
{
|
|
var organizationId = Guid.NewGuid();
|
|
var now = DateTime.UtcNow;
|
|
|
|
var sql = @"
|
|
INSERT INTO organizations (id, name, description, created_by_id)
|
|
VALUES (@Id, @Name, @Description, @CreatedById)";
|
|
|
|
|
|
await db.Connection.ExecuteSqlAsync(sql, new
|
|
{
|
|
Id = organizationId,
|
|
command.Name,
|
|
command.Description,
|
|
CreatedById = command.CreatedById,
|
|
CreatedAt = now,
|
|
UpdatedAt = now
|
|
});
|
|
|
|
db.Success();
|
|
|
|
return new CreateOrganizationResponse
|
|
{
|
|
Id = organizationId,
|
|
Name = command.Name,
|
|
CreatedAt = now
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Error(ex);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
} |