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:
OlgunR
2026-01-16 13:18:56 +01:00
parent ab1f73f987
commit 215e526230

View File

@@ -62,8 +62,7 @@ public class CatalogRepository : ICatalogRepository
var guidParam = new SqlParameter("@GUID", SqlDbType.Int)
{
Direction = ParameterDirection.Input,
Value = id
Direction = ParameterDirection.Output
};
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);
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 },
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)