Implement API security baseline (sys_user, JWT, audit fields, transactions, unique constraints) and Web real login with 401 handling. Document setup and development workflows in root, WmsLite.Api, and WmsLite.Web README files. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
906 B
C#
44 lines
906 B
C#
namespace WmsLite.Api.Infrastructure;
|
|
|
|
public interface ITransactionRunner
|
|
{
|
|
Task<T> ExecuteAsync<T>(Func<Task<T>> action);
|
|
|
|
Task ExecuteAsync(Func<Task> action);
|
|
}
|
|
|
|
public sealed class SqlSugarTransactionRunner : ITransactionRunner
|
|
{
|
|
private readonly SqlSugar.ISqlSugarClient _db;
|
|
|
|
public SqlSugarTransactionRunner(SqlSugar.ISqlSugarClient db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
public async Task<T> ExecuteAsync<T>(Func<Task<T>> action)
|
|
{
|
|
try
|
|
{
|
|
_db.Ado.BeginTran();
|
|
var result = await action();
|
|
_db.Ado.CommitTran();
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
_db.Ado.RollbackTran();
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task ExecuteAsync(Func<Task> action)
|
|
{
|
|
await ExecuteAsync(async () =>
|
|
{
|
|
await action();
|
|
return true;
|
|
});
|
|
}
|
|
}
|