diff options
author | crupest <crupest@outlook.com> | 2022-12-06 18:32:21 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:52 +0800 |
commit | dbef06668f4e8b81eb466faa11bb37709c79f09c (patch) | |
tree | 84ba25cc92cf75e3ac150209c65ad043774144df /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs | |
parent | 46ee538c2ffe3ea76c647524c74c2ce6add8a2d3 (diff) | |
download | crupest-dbef06668f4e8b81eb466faa11bb37709c79f09c.tar.gz crupest-dbef06668f4e8b81eb466faa11bb37709c79f09c.tar.bz2 crupest-dbef06668f4e8b81eb466faa11bb37709c79f09c.zip |
Develop secret api. v14
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs index bbd5e9a..7da6ac7 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs @@ -8,13 +8,13 @@ public class CrudService<TEntity> { protected readonly TableInfo _table; protected readonly IOptionsSnapshot<CrupestApiConfig> _crupestApiOptions; - protected readonly ILogger<CrudService<TEntity>> _logger; + private readonly ILogger<CrudService<TEntity>> _logger; - public CrudService(IOptionsSnapshot<CrupestApiConfig> crupestApiOptions, ILogger<CrudService<TEntity>> logger) + public CrudService(ServiceProvider services) { _table = new TableInfo(typeof(TEntity)); - _crupestApiOptions = crupestApiOptions; - _logger = logger; + _crupestApiOptions = services.GetRequiredService<IOptionsSnapshot<CrupestApiConfig>>(); + _logger = services.GetRequiredService<ILogger<CrudService<TEntity>>>(); } public virtual string GetDbConnectionString() @@ -78,4 +78,12 @@ public class CrudService<TEntity> var sql = _table.GenerateUpdateSql(where, update, out parameters); return await connection.ExecuteAsync(sql, parameters); } + + public virtual async Task<int> DeleteAsync(WhereClause? where) + { + var connection = await EnsureDatabase(); + DynamicParameters parameters; + var sql = _table.GenerateDeleteSql(where, out parameters); + return await connection.ExecuteAsync(sql, parameters); + } } |