Fix gestione creazione KIT con stored corretta
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user