/// <summary> /// Updates the filter. /// </summary> /// <param name="buildDto">The build dto.</param> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.Data.DBConcurrencyException"></exception> public void UpdateFilter(FilterDto buildDto) { if (buildDto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "buildDto")); const string CommandText = @" UPDATE Filters SET ProcessId = @p_ProcessId, Name = @p_Name, FilterDefinition = @p_FilterDefinition WHERE Id = @p_id "; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var cn = ctx.Connection; if (cn.State != ConnectionState.Open) { cn.Open(); } using (var command = new SqlCommand(CommandText, cn)) { command.Parameters.AddWithValue("@p_ProcessId", buildDto.ProcessId); command.Parameters.AddWithValue("@p_Name", buildDto.Name); command.Parameters.AddWithValue("@p_FilterDefinition", buildDto.FilterDefinition); command.Parameters.AddWithValue("@p_id", buildDto.Id); var rowsAffetcted = command.ExecuteNonQuery(); if (rowsAffetcted == 0) throw new DBConcurrencyException(Resources.StaleDataException); } } }
public void FilterInfo_CreateNewInstance_PropertiesAreSet() { const string XmlValue = "<test></test>"; TextReader txt = new StringReader(XmlValue); XmlReader reader = new XmlTextReader(txt); var dto = new FilterDto { FilterDefinition = new SqlXml(reader), Id = 1, Name = "name", ProcessId = 2 }; var filter = new FilterInfo(dto); Assert.AreEqual(dto.Id, filter.Id); Assert.AreEqual(dto.Name, filter.Name); Assert.AreEqual(dto.FilterDefinition.Value, filter.FilterDefinition); }
/// <summary> /// Fetches the filter. /// </summary> /// <param name="id">The identifier.</param> /// <returns>FilterDto.</returns> public FilterDto FetchFilter(int id) { const string CommandText = @" SELECT TOP 1000 [Id] ,[ProcessId] ,[UserId] ,[Name] ,[FilterDefinition] FROM [Filters] WHERE Id = @id"; var result = new FilterDto(); using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var cn = ctx.Connection; if (cn.State != ConnectionState.Open) { cn.Open(); } using (var cmd = new SqlCommand(CommandText, cn)) { cmd.Parameters.AddWithValue("@id", id); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { result = new FilterDto { Id = reader.GetInt32(0), Name = reader.GetString(3), FilterDefinition = reader.GetSqlXml(4) }; } } } } return result; }
/// <summary> /// Inserts the filter. /// </summary> /// <param name="dto">The dto.</param> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.Data.DBConcurrencyException"></exception> public void InsertFilter(FilterDto dto) { if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "childData")); const string CommandText = @" INSERT INTO [Filters] ([ProcessId] ,[Name] ,[FilterDefinition]) VALUES (@p_ProcessId ,@p_Name ,@p_FilterDefinition) SET @p_id = SCOPE_IDENTITY() "; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var cn = ctx.Connection; if (cn.State != ConnectionState.Open) { cn.Open(); } using (var command = new SqlCommand(CommandText, cn)) { command.Parameters.AddWithValue("@p_ProcessId", dto.ProcessId); command.Parameters.AddWithValue("@p_Name", dto.Name); command.Parameters.AddWithValue("@p_FilterDefinition", dto.FilterDefinition); var idParam = new SqlParameter("@p_id", SqlDbType.Int, 0, "Id") { Direction = ParameterDirection.Output }; command.Parameters.Add(idParam); var rowsAffetcted = command.ExecuteNonQuery(); if (rowsAffetcted == 0) throw new DBConcurrencyException(Resources.StaleDataException); dto.Id = (int)idParam.Value; } } }