55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Utils;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MySqlConnector;
|
|
using System.Data;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Repository.Utils
|
|
{
|
|
public class CounterRepository : BaseRepository, ICounterRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public CounterRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public async Task<List<CounterModel>> 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<int> 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
|
|
}
|
|
}
|