I clean up some old code.
Please provide your insight on using UpdateDataAsyncInternal. Will it enhance the code’s security? Should we remove UpdateDataAsyncInternal and consolidate all the logic in UpdateDataAsync instead? This approach could lead to cleaner code and simplify the creation of test cases. Any input would be greatly appreciated. Thank you!
public class GetStuffFromDBService(IConfiguration config) : IGetStuffFromDBService
{
private readonly IConfiguration _config = config;
public async Task<DetailsOutputDTO> UpdateDataAsync(DetailsOutputDTO detailsInputDTO)
=> await UpdateDataAsyncInternal(detailsInputDTO);
private static async Task<DetailsOutputDTO> UpdateDataAsyncInternal(DetailsOutputDTO detailsInputDTO)
{
try
{
using SqlConnection con = new(config.ConnectionStrings.ConnectionString1);
await con.OpenAsync();
using SqlCommand com = ...
var results = await com.ExecuteNonQueryAsync();
message = "Good";
IsSuccess = true;
}
catch (Exception ex)
{
await new ErrorLogService().LogError(
new ErrorLog()
{
...
});
message = "something went wrong"; //ex.Message;
IsSuccess = false;
}
return new DetailsOutputDTO() { IsSuccess = IsSuccess, Message = message};
}
}
}