/// <summary> /// Updates reverse cross ref options step. /// </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 UpdateReverseCrossRefOptionsStep(ReverseCrossRefOptionsStepDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string CommandText = @" UPDATE [dbo].[ReverseCrossRefOptionsFieldStep] SET [FieldId] = @fieldId ,[LastModifiedOn] = GETDATE() ,[AllowAddNew] = @allowAddNew ,[AllowLink] = @allowLink ,[ShowLatestVersion] = @showLatestVersion WHERE [Id] = @stepId;"; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var cn = ctx.Connection; using (var cmd = new SqlCommand(CommandText, cn)) { cmd.Parameters.AddWithValue("@stepId", dto.Id); cmd.Parameters.AddWithValue("@fieldId", dto.FieldId); cmd.Parameters.AddWithValue("allowAddNew", dto.AllowAddNew); cmd.Parameters.AddWithValue("allowLink", dto.AllowLink); cmd.Parameters.AddWithValue("@showLatestVersion", dto.ShowLatestVersion); var rowsAffetcted = cmd.ExecuteNonQuery(); if (rowsAffetcted == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } } }
/// <summary> /// Retrieves reverse cross ref options step. /// </summary> /// <param name="processName">The process name.</param> /// <param name="fieldName">The field name.</param> /// <param name="isPublishedCopy">The is published copy.</param> /// <returns>The <see cref="ReverseCrossRefOptionsStepDto" />.</returns> public ReverseCrossRefOptionsStepDto FetchReverseCrossRefOptionsStep(string processName, string fieldName, bool isPublishedCopy = false) { const string CmdText = @" DECLARE @fieldId AS INT SELECT @fieldId = f.Id FROM [dbo].[Processes] p INNER JOIN [dbo].[Sections] s ON s.ProcessId = p.Id INNER JOIN [dbo].[Fields] f ON f.SectionId = s.Id WHERE p.[SystemName] = @processName AND p.IsRemoved = 0 AND p.IsPublishedCopy = @isPublishedCopy AND f.SystemName = @fieldName; EXEC [dbo].[GetReverseCrossRefOptionsStep] @FieldId = @fieldId; "; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) using (var cmd = new SqlCommand(CmdText, ctx.Connection)) { cmd.Parameters.AddWithValue("@processName", processName); cmd.Parameters.AddWithValue("@fieldName", fieldName); cmd.Parameters.AddWithValue("@isPublishedCopy", isPublishedCopy); using (var reader = new SafeDataReader(cmd.ExecuteReader())) { if (reader.Read()) { var dto = new ReverseCrossRefOptionsStepDto { Id = reader.GetInt(0), FieldId = reader.GetInt(1), AllowAddNew = reader.GetBoolean(2), AllowLink = reader.GetBoolean(3), ShowLatestVersion = reader.GetBoolean(4) }; return dto; } } } return null; }
/// <summary> /// Inserts reverse cross ref options step. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception> public void InsertReverseCrossRefOptionsStep(ReverseCrossRefOptionsStepDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string CommandText = @" INSERT INTO [dbo].[ReverseCrossRefOptionsFieldStep] ( [FieldId] ,[LastModifiedOn] ,[AllowAddNew] ,[AllowLink] ,[ShowLatestVersion] ) VALUES ( @fieldId ,GETDATE() ,@allowAddNew ,@allowLink ,@showLatestVersion ) SELECT [Id] FROM [dbo].[ReverseCrossRefOptionsFieldStep] WHERE [Id] = SCOPE_IDENTITY();"; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var cn = ctx.Connection; using (var cmd = new SqlCommand(CommandText, cn)) { cmd.Parameters.AddWithValue("@fieldId", dto.FieldId); cmd.Parameters.AddWithValue("@allowAddNew", dto.AllowAddNew); cmd.Parameters.AddWithValue("@allowLink", dto.AllowLink); cmd.Parameters.AddWithValue("@showLatestVersion", dto.ShowLatestVersion); dto.Id = (int)cmd.ExecuteScalar(); } } }