Various work around the architecture
This commit is contained in:
parent
b1e134490d
commit
71576a4b1f
18 changed files with 522 additions and 358 deletions
|
|
@ -0,0 +1,52 @@
|
|||
using Insight.Database;
|
||||
|
||||
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, CreatedById, CreatedAt, UpdatedAt)
|
||||
VALUES (@Id, @Name, @Description, @CreatedById, @CreatedAt, @UpdatedAt)";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue