public CreateTicketResponseBlModel( StoredProcedureExecutionResult result, int ticketId ) { Result = result; TicketId = ticketId; }
public async Task <IActionResult> Delete(int id) { StoredProcedureExecutionResult result = await _serviceService.DeleteService(id); if (result == StoredProcedureExecutionResult.ForeignKeyViolation) { return(BadRequest(HttpStatusCode.Conflict)); } return(Accepted()); }
public StoredProcedureExecutionResult ExecuteProcedure(string procedureName, IEnumerable <Parameter> inputParameters) { StoredProcedureExecutionResult result = null; try { result = this.IDatabaseService.ExecuteProcedure(this.DBConnection, procedureName, inputParameters); } catch (Exception ex) { throw; } return(result); }
/// <inheritdoc /> public StoredProcedureExecutionResult Execute( ExecuteStoredProcedureOp operation) { var outputParametersWithExecutionResult = new Dictionary <string, ISqlOutputParameterResult>(); using (var sqlConnection = this.sqlServerLocator.OpenSqlConnection(this.defaultConnectionTimeout)) { using (var command = sqlConnection.BuildSqlCommand(operation.Name, (int)this.defaultCommandTimeout.TotalSeconds)) { command.CommandType = CommandType.StoredProcedure; var outputParameters = new List <Tuple <SqlParameter, OutputParameterDefinitionBase> >(); foreach (var parameterRepresentation in operation.Parameters) { var parameter = parameterRepresentation.ToSqlParameter(); if (parameter.Direction == ParameterDirection.Output) { if (parameterRepresentation is OutputParameterDefinitionBase outputParameterRepresentation) { outputParameters.Add(new Tuple <SqlParameter, OutputParameterDefinitionBase>(parameter, outputParameterRepresentation)); } else { throw new NotSupportedException(FormattableString.Invariant($"Cannot have a {nameof(SqlParameter)} with {nameof(SqlParameter.Direction)} equal to {nameof(ParameterDirection.Output)} and the representation not be a {nameof(OutputParameterDefinitionBase)}, it was a {parameterRepresentation.GetType().ToStringReadable()}.")); } } command.Parameters.Add(parameter); } command.ExecuteNonQuery(); foreach (var outputParameter in outputParameters) { var outputParameterWithResult = outputParameter.Item2.CreateResult(outputParameter.Item1.Value); outputParametersWithExecutionResult.Add(outputParameter.Item2.Name, outputParameterWithResult); } } } var result = new StoredProcedureExecutionResult(operation, outputParametersWithExecutionResult); return(result); }
static StoredProcedureExecutionResultTest() { ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <StoredProcedureExecutionResult> { Name = "constructor should throw ArgumentNullException when parameter 'operation' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <StoredProcedureExecutionResult>(); var result = new StoredProcedureExecutionResult( null, referenceObject.OutputParameters); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "operation", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <StoredProcedureExecutionResult> { Name = "constructor should throw ArgumentNullException when parameter 'outputParameters' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <StoredProcedureExecutionResult>(); var result = new StoredProcedureExecutionResult( referenceObject.Operation, null); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "outputParameters", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <StoredProcedureExecutionResult> { Name = "constructor should throw ArgumentException when parameter 'outputParameters' contains a key-value pair with a null value scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <StoredProcedureExecutionResult>(); var dictionaryWithNullValue = referenceObject.OutputParameters.ToDictionary(_ => _.Key, _ => _.Value); var randomKey = dictionaryWithNullValue.Keys.ElementAt(ThreadSafeRandom.Next(0, dictionaryWithNullValue.Count)); dictionaryWithNullValue[randomKey] = null; var result = new StoredProcedureExecutionResult( referenceObject.Operation, dictionaryWithNullValue); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "outputParameters", "contains at least one key-value pair with a null value", }, }); }