Update catalog update to use OUTPUT GUID from stored proc
Refactored CatalogRepository to set @GUID as an OUTPUT parameter when calling PRTBMY_CATALOG_UPDATE. Now, after execution, the code checks the returned GUID value and uses it to fetch the updated catalog entry, handling cases where the GUID is null or zero. This ensures the repository returns the correct catalog record as modified by the stored procedure.
This commit is contained in:
@@ -62,8 +62,7 @@ public class CatalogRepository : ICatalogRepository
|
|||||||
|
|
||||||
var guidParam = new SqlParameter("@GUID", SqlDbType.Int)
|
var guidParam = new SqlParameter("@GUID", SqlDbType.Int)
|
||||||
{
|
{
|
||||||
Direction = ParameterDirection.Input,
|
Direction = ParameterDirection.Output
|
||||||
Value = id
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var catTitleParam = new SqlParameter("@CAT_TITLE", catalog.CatTitle);
|
var catTitleParam = new SqlParameter("@CAT_TITLE", catalog.CatTitle);
|
||||||
@@ -71,11 +70,22 @@ public class CatalogRepository : ICatalogRepository
|
|||||||
var changedWhoParam = new SqlParameter("@CHANGED_WHO", (object?)catalog.ChangedWho ?? DBNull.Value);
|
var changedWhoParam = new SqlParameter("@CHANGED_WHO", (object?)catalog.ChangedWho ?? DBNull.Value);
|
||||||
|
|
||||||
await _db.Database.ExecuteSqlRawAsync(
|
await _db.Database.ExecuteSqlRawAsync(
|
||||||
"EXEC dbo.PRTBMY_CATALOG_UPDATE @CAT_TITLE, @CAT_STRING, @CHANGED_WHO, @GUID",
|
"EXEC dbo.PRTBMY_CATALOG_UPDATE @CAT_TITLE, @CAT_STRING, @CHANGED_WHO, @GUID OUTPUT",
|
||||||
parameters: new[] { catTitleParam, catStringParam, changedWhoParam, guidParam },
|
parameters: new[] { catTitleParam, catStringParam, changedWhoParam, guidParam },
|
||||||
cancellationToken: cancellationToken);
|
cancellationToken: cancellationToken);
|
||||||
|
|
||||||
return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == id, cancellationToken);
|
if (guidParam.Value == DBNull.Value)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var guid = (int)guidParam.Value;
|
||||||
|
if (guid == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == guid, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default)
|
public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
|||||||
Reference in New Issue
Block a user