using Knoks.Core.Data.Interfaces; using Knoks.Core.Entities; using Knoks.Core.Entities.Args; using Knoks.Framework.DataAccess; using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Knoks.Core.Data.Dao { public class OperatorDao : IOperatorDao { private readonly IProcExecutor _executor; private readonly ILogger _logger; public OperatorDao(ILogger logger, IProcExecutor executor) { _logger = logger; _executor = executor; } public async Task CreateOperator(CreateOperatorArgs args) { return (await _executor.Go("REG_CreateOperator", args)).Тables[0][0].To(); } public async Task> GetOperators(int? operatorId = null) { _logger.LogDebug("GetOperators : {0}", operatorId); return (await _executor.Go("REG_GetOperators", new { OperatorId = operatorId })).Тables[0].Rows.Select(row => row.To()); } public async Task GetOperatorCredential(int apiConsumerId, string operatorName) { _logger.LogDebug($"GetOperatorCredential: {nameof(operatorName)}='{operatorName}'"); var dataResult = await _executor.Go("REG_GetOperatorCredential", new { ApiConsumerId = apiConsumerId, OperatorName = operatorName }); return dataResult.Тables[0].Rows.Count != 1 ? null : new OperatorCredential { Operator = dataResult.Тables[0][0].To(), OperatorPassword = dataResult.OutputParams["OperatorPassword"].ToString() }; } } }