/// <summary> /// Inserts data trigger field mapping data source. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception> /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception> public void InsertDataTriggerFieldMappingDataSource(DataTriggerFieldMappingDataSourceDto dto) { if (dto == null) throw new ArgumentNullException("dto"); const string CommandText = @" INSERT INTO [dbo].[DataTriggerFieldMappingDataSources] ( [Guid] ,[MappingId] ,[LastModifiedOn] ,[Name] ,[SourcePath] ,[IncludeNewItems] ,[IncludeOldItems] ,[IncludeRemovedItems] ) VALUES ( @guid ,@mappingId ,GETDATE() ,@name ,@sourcePath ,@includeNewItems ,@includeOldItems ,@includeRemovedItems ) SET @id = SCOPE_IDENTITY();"; using (var cmd = new SqlCommand(CommandText)) { var idParam = cmd.Parameters.Add("@id", SqlDbType.Int); idParam.Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@guid", dto.Guid); cmd.Parameters.AddWithValue("@mappingId", dto.MappingId); cmd.Parameters.AddWithValue("@name", dto.Name); cmd.Parameters.AddWithValue("@sourcePath", dto.SourcePath); cmd.Parameters.AddWithValue("@includeNewItems", dto.IncludeNewItems); cmd.Parameters.AddWithValue("@includeOldItems", dto.IncludeOldItems); cmd.Parameters.AddWithValue("@includeRemovedItems", dto.IncludeRemovedItems); if (Database.Execute(cmd) == 0) throw new DBConcurrencyException(Resources.StaleDataException); dto.Id = (int)idParam.Value; } }
/// <summary> /// Updates data trigger field mapping data source. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception> /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception> public void UpdateDataTriggerFieldMappingDataSource(DataTriggerFieldMappingDataSourceDto dto) { if (dto == null) throw new ArgumentNullException("dto"); const string CommandText = @" UPDATE [dbo].[DataTriggerFieldMappingDataSources] SET [Guid] = @guid ,[MappingId] = @mappingId ,[LastModifiedOn] = GETDATE() ,[Name] = @name ,[SourcePath] = @sourcePath ,[IncludeNewItems] = @includeNewItems ,[IncludeOldItems] = @includeOldItems ,[IncludeRemovedItems] = @includeRemovedItems WHERE [Id] = @id"; using (var cmd = new SqlCommand(CommandText)) { cmd.Parameters.AddWithValue("@id", dto.Id); cmd.Parameters.AddWithValue("@guid", dto.Guid); cmd.Parameters.AddWithValue("@mappingId", dto.MappingId); cmd.Parameters.AddWithValue("@name", dto.Name); cmd.Parameters.AddWithValue("@sourcePath", dto.SourcePath); cmd.Parameters.AddWithValue("@includeNewItems", dto.IncludeNewItems); cmd.Parameters.AddWithValue("@includeOldItems", dto.IncludeOldItems); cmd.Parameters.AddWithValue("@includeRemovedItems", dto.IncludeRemovedItems); if (Database.Execute(cmd) == 0) throw new DBConcurrencyException(Resources.StaleDataException); } }
/// <summary> /// Reads data trigger field mapping data sources. /// </summary> /// <param name="process">The process.</param> /// <param name="sr">The reader.</param> private static void ReadDataTriggerFieldMappingDataSources(ProcessEditDto process, SafeDataReader sr) { sr.NextResult(); int? mappingId = null; DataTriggerFieldMappingEditDto mapping = null; while (sr.Read()) { var dataSourceDto = new DataTriggerFieldMappingDataSourceDto { Id = sr.GetInt32(0), Guid = sr.GetGuid(1), MappingId = sr.GetInt32(2), Name = sr.GetString(3), SourcePath = sr.GetString(4), IncludeNewItems = sr.GetBoolean(5), IncludeOldItems = sr.GetBoolean(6), IncludeRemovedItems = sr.GetBoolean(7) }; if (dataSourceDto.MappingId != mappingId) { mapping = process.TriggerList.SelectMany(t => t.FieldMappingList).First(m => m.Id == dataSourceDto.MappingId); mappingId = dataSourceDto.MappingId; } mapping.DataSources.Add(dataSourceDto); } }