/// <summary> /// Inserts the integration service method. /// </summary> /// <param name="dto">The dto.</param> /// <exception cref="System.ArgumentNullException">dto</exception> /// <exception cref="System.Data.DBConcurrencyException"></exception> public void InsertIntegrationServiceMethod(IntegrationServiceMethodDto dto) { const string CommandText = @" INSERT INTO [dbo].[IntegrationServiceMethods] ( [SettingsId] ,[LastModifiedOn] ,[Guid] ,[Name] ,[Namespace] ,[Username] ,[Password] ,[CanInsert] ,[CanUpdate] ,[CanInsertOrUpdate] ,[CanRemove] ,[CanSelect] ,[EndpointMapping] ,[GenerateIndexes] ,[ResultTypeGuid] ,[ResultMapping] ,[ReturnMode] ) VALUES ( @settingsId ,GETDATE() ,@guid ,@name ,@namespace ,@username ,@password ,@canInsert ,@canUpdate ,@canInsertOrUpdate ,@canRemove ,@canSelect ,@endpointMapping ,@generateIndexes ,@resultTypeGuid ,@resultMapping ,@returnMode ); SET @id = SCOPE_IDENTITY();"; if (dto == null) throw new ArgumentNullException("dto"); using (var cmd = new SqlCommand(CommandText)) { var idParam = cmd.Parameters.Add("@id", SqlDbType.Int); idParam.Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@settingsId", dto.SettingsId); cmd.Parameters.AddWithValue("@guid", dto.Guid); cmd.Parameters.AddWithValue("@name", dto.Name); cmd.Parameters.AddWithValue("@namespace", dto.Namespace); cmd.Parameters.AddWithValue("@username", dto.Username); cmd.Parameters.AddWithValue("@password", dto.Password); cmd.Parameters.AddWithValue("@canInsert", dto.CanInsert); cmd.Parameters.AddWithValue("@canUpdate", dto.CanUpdate); cmd.Parameters.AddWithValue("@canInsertOrUpdate", dto.CanInsertOrUpdate); cmd.Parameters.AddWithValue("@canRemove", dto.CanRemove); cmd.Parameters.AddWithValue("@canSelect", dto.CanSelect); cmd.Parameters.AddWithValue("@endpointMapping", dto.EndpointMapping); cmd.Parameters.AddWithValue("@generateIndexes", dto.GenerateIndexes); cmd.Parameters.AddWithValue("@resultTypeGuid", AdoHelper.NullCheck(dto.ResultTypeGuid)); cmd.Parameters.AddWithValue("@resultMapping", dto.ResultMapping); cmd.Parameters.AddWithValue("@returnMode", dto.ReturnMode.ToString()); var rowsAffected = Database.Execute(cmd); if (rowsAffected == 0) throw new DBConcurrencyException(ConcurencyException); dto.Id = (int)idParam.Value; } }
/// <summary> /// Updates the integration service method. /// </summary> /// <param name="dto">The dto.</param> /// <exception cref="System.ArgumentNullException">dto</exception> /// <exception cref="System.Data.DBConcurrencyException"></exception> public void UpdateIntegrationServiceMethod(IntegrationServiceMethodDto dto) { const string CommandText = @" UPDATE [dbo].[IntegrationServiceMethods] SET [SettingsId] = @settingsId ,[LastModifiedOn] = GETDATE() ,[Guid] = @guid ,[Name] = @name ,[Namespace] = @namespace ,[Username] = @username ,[Password] = @password ,[CanInsert] = @canInsert ,[CanUpdate] = @canUpdate ,[CanInsertOrUpdate] = @canInsertOrUpdate ,[CanRemove] = @canRemove ,[CanSelect] = @canSelect ,[EndpointMapping] = @endpointMapping ,[GenerateIndexes] = @generateIndexes ,[ResultTypeGuid] = @resultTypeGuid ,[ResultMapping] = @resultMapping ,[ReturnMode] = @returnMode WHERE [Id] = @id;"; if (dto == null) throw new ArgumentNullException("dto"); using (var cmd = new SqlCommand(CommandText)) { cmd.Parameters.AddWithValue("@id", dto.Id); cmd.Parameters.AddWithValue("@settingsId", dto.SettingsId); cmd.Parameters.AddWithValue("@guid", dto.Guid); cmd.Parameters.AddWithValue("@name", dto.Name); cmd.Parameters.AddWithValue("@namespace", dto.Namespace); cmd.Parameters.AddWithValue("@username", dto.Username); cmd.Parameters.AddWithValue("@password", dto.Password); cmd.Parameters.AddWithValue("@canInsert", dto.CanInsert); cmd.Parameters.AddWithValue("@canUpdate", dto.CanUpdate); cmd.Parameters.AddWithValue("@canInsertOrUpdate", dto.CanInsertOrUpdate); cmd.Parameters.AddWithValue("@canRemove", dto.CanRemove); cmd.Parameters.AddWithValue("@canSelect", dto.CanSelect); cmd.Parameters.AddWithValue("@endpointMapping", dto.EndpointMapping); cmd.Parameters.AddWithValue("@generateIndexes", dto.GenerateIndexes); cmd.Parameters.AddWithValue("@resultTypeGuid", AdoHelper.NullCheck(dto.ResultTypeGuid)); cmd.Parameters.AddWithValue("@resultMapping", dto.ResultMapping); cmd.Parameters.AddWithValue("@returnMode", dto.ReturnMode.ToString()); var rowsAffected = Database.Execute(cmd); if (rowsAffected == 0) throw new DBConcurrencyException(ConcurencyException); } }
/// <summary> /// Reads the integration service methods. /// </summary> /// <param name="settingsDto">The settings dto.</param> /// <param name="reader">The reader.</param> private static void ReadIntegrationServiceMethods(IntegrationServiceCreationSettingsDto settingsDto, SafeDataReader reader) { reader.NextResult(); while (reader.Read()) { var dto = new IntegrationServiceMethodDto { Id = reader.GetInt32(0), Guid = reader.GetGuid(1), Name = reader.GetString(2), Username = reader.GetString(3), Password = reader.GetString(4), CanInsert = reader.GetBoolean(5), CanUpdate = reader.GetBoolean(6), CanInsertOrUpdate = reader.GetBoolean(7), CanRemove = reader.GetBoolean(8), EndpointMapping = reader.GetString(9), Namespace = reader.GetString(10), CanSelect = reader.GetBoolean("CanSelect"), ResultTypeGuid = reader.GetNullableGuid("ResultTypeGuid"), ResultMapping = reader.GetString("ResultMapping"), ReturnMode = reader.GetEnum("ReturnMode", IntegrationServiceMethodReturnMode.All), GenerateIndexes = reader.GetBoolean("GenerateIndexes") }; settingsDto.Methods.Add(dto); } ReadIntegrationServiceMethodParameters(settingsDto, reader); }