Fix gestione creazione KIT con stored corretta

This commit is contained in:
Samuele Locatelli
2026-06-08 12:01:05 +02:00
parent 3499d8b32d
commit e6df6a5e18
7 changed files with 61 additions and 99 deletions
+16 -46
View File
@@ -27,55 +27,25 @@ namespace MP.Data.Repository.Anag
{
AnagCountersModel answ = new AnagCountersModel();
await using var dbCtx = await CreateContextAsync();
bool outTable = true;
if (outTable)
{
var pCntType = new SqlParameter("@CntType", cntType);
var pLastNum = new SqlParameter
{
ParameterName = "@LastNum",
SqlDbType = SqlDbType.Int,
Direction = ParameterDirection.Output
};
var dbResult = await dbCtx
.DbSetAnagCount
.FromSqlRaw("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT", pCntType, pLastNum)
.AsNoTracking()
.FirstOrDefaultAsync();
if (dbResult != null)
{
answ = dbResult;
}
}
else
var pCntType = new SqlParameter("@CntType", cntType);
var pLastNum = new SqlParameter
{
// se si volessero impiegare parametri OUTPUT (qui ne mancherebbe 1 nella stored x CntCode...)
var pCntType = new SqlParameter("@CntType", cntType);
var pLastNum = new SqlParameter
{
ParameterName = "@LastNum",
SqlDbType = SqlDbType.Int,
Direction = ParameterDirection.Output
};
var pCntCode = new SqlParameter
{
ParameterName = "@CntCode",
SqlDbType = SqlDbType.NVarChar,
Direction = ParameterDirection.Output
};
var dbResult = await dbCtx
.Database
.ExecuteSqlRawAsync("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT, @CntCode OUTPUT", pCntType, pLastNum, pCntCode);
if (dbResult != 0)
{
answ.CntType = cntType;
answ.CntCode = $"{pCntCode.Value}";
int lNum = 0;
int.TryParse($"{pLastNum.Value}", out lNum);
answ.LastNum = lNum;
}
ParameterName = "@LastNum",
SqlDbType = SqlDbType.Int,
Direction = ParameterDirection.Output
};
var dbResult = (await dbCtx
.DbSetAnagCount
.FromSqlRaw("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT", pCntType, pLastNum)
.AsNoTracking()
.ToListAsync()).FirstOrDefault();
if (dbResult != null)
{
answ = dbResult;
}
return answ;
}