/// <summary> /// Updates checklist display field. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception> public void UpdateChecklistDisplayField(ChecklistDisplayFieldDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string CommandText = @" UPDATE [dbo].[ChecklistDisplayFields] SET [LastModifiedOn] = GETDATE() , [FieldId] = @fieldId , [SystemName] = @systemName , [Sequence] = @sequence , [Width] = @width , [NumberOfRows] = @numberOfRows WHERE [Id] = @id;"; using (var cmd = new SqlCommand(CommandText)) { cmd.Parameters.AddWithValue("@id", dto.Id); cmd.Parameters.AddWithValue("@fieldId", dto.FieldId); cmd.Parameters.AddWithValue("@systemName", dto.SystemName); cmd.Parameters.AddWithValue("@sequence", dto.Sequence); cmd.Parameters.AddWithValue("@width", dto.Width); cmd.Parameters.AddWithValue("@numberOfRows", dto.NumberOfRows); Database.Execute(cmd); } }
/// <summary> /// Inserts checklist display field. /// </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 InsertChecklistDisplayField(ChecklistDisplayFieldDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string CommandText = @" INSERT INTO [dbo].[ChecklistDisplayFields] ( [LastModifiedOn] , [FieldId] , [SystemName] , [Sequence] , [Width] , [NumberOfRows] ) VALUES ( GETDATE() , @fieldId , @systemName , @sequence , @width , @numberOfRows ); 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("@fieldId", dto.FieldId); cmd.Parameters.AddWithValue("@systemName", dto.SystemName); cmd.Parameters.AddWithValue("@sequence", dto.Sequence); cmd.Parameters.AddWithValue("@width", dto.Width); cmd.Parameters.AddWithValue("@numberOfRows", dto.NumberOfRows); var rowsAffetcted = Database.Execute(cmd); if (rowsAffetcted == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } dto.Id = (int)idParam.Value; } }