From 215e526230de01849eadcaafeca055e5db0e8409 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Fri, 16 Jan 2026 13:18:56 +0100 Subject: [PATCH] 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. --- .../Repositories/CatalogRepository.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/DbFirst.Infrastructure/Repositories/CatalogRepository.cs b/DbFirst.Infrastructure/Repositories/CatalogRepository.cs index f37ed80..37e8d0a 100644 --- a/DbFirst.Infrastructure/Repositories/CatalogRepository.cs +++ b/DbFirst.Infrastructure/Repositories/CatalogRepository.cs @@ -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 DeleteAsync(int id, CancellationToken cancellationToken = default)