using MySqlConnector; using System.Data; namespace EgwCoreLib.Lux.Data.Repository.Utils { public class CounterRepository : BaseRepository, ICounterRepository { #region Public Constructors public CounterRepository(IDbContextFactory ctxFactory) : base(ctxFactory) { } #endregion Public Constructors #region Public Methods /// public async Task> GetAllAsync(int? yearRef = null) { await using var dbCtx = await CreateContextAsync(); return await dbCtx.DbSetCounters .AsNoTracking() .Where(x => yearRef == null || x.RefYear == yearRef) .ToListAsync(); } /// public async Task GetNextAsync(int yearRef, string countName) { await using var dbCtx = await CreateContextAsync(); int newCount = 0; var outParam = new MySqlParameter("@pValue", MySqlDbType.Int32) { Direction = ParameterDirection.Output }; await dbCtx.Database.ExecuteSqlRawAsync( "CALL GetNextCounter(@pYear, @pName, @pValue);", new MySqlParameter("@pYear", yearRef), new MySqlParameter("@pName", countName), outParam ); if (outParam != null) { int.TryParse($"{outParam.Value}", out newCount); } return newCount; } #endregion Public Methods } }