Refactor SQL construction with StringBuilder for clarity
Refactored DeleteObjectProcedureHandler, InsertObjectProcedureHandler, and UpdateObjectProcedureHandler to use StringBuilder for building SQL command strings. This improves readability and maintainability without changing the logic or parameters. Added System.Text using directives as needed.
This commit is contained in:
@@ -5,6 +5,7 @@ using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ReC.Application.Common.Exceptions;
|
||||
using ReC.Application.Common.Options;
|
||||
using System.Text;
|
||||
|
||||
namespace ReC.Application.Common.Procedures.DeleteProcedure;
|
||||
|
||||
@@ -45,13 +46,17 @@ public class DeleteObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlE
|
||||
|
||||
try
|
||||
{
|
||||
var result = await repo.ExecuteQueryRawAsync(
|
||||
"DECLARE @RC SMALLINT = 0; " +
|
||||
"EXEC @RC = [dbo].[PRREC_DELETE_OBJECT] " +
|
||||
"@pENTITY = @pENTITY, @pSTART = @pSTART, @pEND = @pEND, @pFORCE = @pFORCE; " +
|
||||
"SELECT @RC;",
|
||||
parameters,
|
||||
cancel);
|
||||
var sql = new StringBuilder()
|
||||
.AppendLine("DECLARE @RC SMALLINT = 0;")
|
||||
.AppendLine("EXEC @RC = [dbo].[PRREC_DELETE_OBJECT]")
|
||||
.AppendLine(" @pENTITY = @pENTITY,")
|
||||
.AppendLine(" @pSTART = @pSTART,")
|
||||
.AppendLine(" @pEND = @pEND,")
|
||||
.AppendLine(" @pFORCE = @pFORCE;")
|
||||
.AppendLine("SELECT @RC;")
|
||||
.ToString();
|
||||
|
||||
var result = await repo.ExecuteQueryRawAsync(sql, parameters, cancel);
|
||||
|
||||
// The stored procedure returns 0 on success, error codes > 0 on failure
|
||||
if (result > 0)
|
||||
|
||||
Reference in New Issue
Block a user