/// <summary> /// Updates date required settings. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException">Indicates stale data.</exception> /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception> public void UpdateDateRequiredSettings(DateRequiredSettingsStepDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; const string CommandText = @" UPDATE [dbo].[stepDateRequiredSettings] SET [FieldId] = @ID, [DateTimeFormat] = @format WHERE [FieldId] = @ID"; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@ID", dto.FieldId); command.Parameters.AddWithValue("@format", dto.DateTimeFormat ?? (object)DBNull.Value); if (command.ExecuteNonQuery() == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } } }
/// <summary> /// Inserts date required settings. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data</exception> /// <exception cref="System.ArgumentException">The input DTO is null.</exception> public void InsertDateRequiredSettings(DateRequiredSettingsStepDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; const string CommandText = @" INSERT INTO [dbo].[stepDateRequiredSettings] ( [FieldId] ,[DateTimeFormat] ) VALUES ( @p_FieldId ,@p_DateTimeFormat )"; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_FieldId", dto.FieldId); command.Parameters.AddWithValue("@p_DateTimeFormat", string.IsNullOrEmpty(dto.DateTimeFormat) ? "DateTime" : dto.DateTimeFormat); if (command.ExecuteNonQuery() == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } } }
/// <summary> /// Retrieves date required settings. /// </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="DateRequiredSettingsStepDto" />.</returns> public DateRequiredSettingsStepDto FetchDateRequiredSettings(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].[GetDateRequiredStep] @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 dbo = new DateRequiredSettingsStepDto { DateTimeFormat = reader.GetString(1) }; return dbo; } } } return null; }