12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using AipDatabase.API.Infrastructures;
- using AipDatabase.API.Interfaces;
- using AipDatabase.API.Models;
- using Dapper;
- using Microsoft.Data.SqlClient;
- using System.Data;
- namespace AipDatabase.API.Repositories
- {
- public class LinkedApiKeyRepository : ILinkedApiKeyRepository
- {
- private readonly ILogger<LinkedApiKeyRepository> _log;
- private readonly IDatabaseFactory _databaseFactory;
- private readonly SqlHelper<LinkedApiKeyRepository> _sqlHelper;
-
- public LinkedApiKeyRepository(ILogger<LinkedApiKeyRepository> log, IDatabaseFactory databaseFactory)
- {
- _log = log;
- _databaseFactory = databaseFactory;
- _sqlHelper = new SqlHelper<LinkedApiKeyRepository>();
- }
- public async Task<Pagination<LinkedApiKey>> GetLists(int pagePerCount, int pageSize, int page, int systemId)
- {
- try
- {
- using var connection = _databaseFactory.GetDbConnection();
- var parameters1 = new
- {
- systemId
- };
- string sql = _sqlHelper.GetSqlFromEmbeddedResource("LinkedApiKey.GetListsTotal");
- Int64 totalCount = await connection.QueryFirstAsync<Int64>(
- sql,
- parameters1,
- commandType: CommandType.Text
- );
- _log.LogInformation($"LinkedApiKey.GetListsTotal: {totalCount} EA.");
- Pagination<LinkedApiKey> result = new Pagination<LinkedApiKey>(page, pageSize, pagePerCount, (int)totalCount);
- var parameters2 = new
- {
- systemId,
- startRow = result.startRow,
- endRow = result.endRow
- };
- sql = _sqlHelper.GetSqlFromEmbeddedResource("LinkedApiKey.GetLists");
- IEnumerable<LinkedApiKey> Results = await connection.QueryAsync<LinkedApiKey>(
- sql,
- parameters2,
- commandType: CommandType.Text
- );
- result.lists = Results.ToList();
- return result;
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|