Exemple #1
0
        /// <summary>
        /// Inserts basic validation 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 InsertBasicValidationStep(BasicValidationStepDto 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].[ValidationStep]
           ([FieldId]
           ,[IsRequired]
           ,[LastUpdatedOn] )
     VALUES
           (@p_FieldId
           ,@p_IsRequired
           ,@p_lastUpdatedOn)
    SET @p_id = SCOPE_IDENTITY()";

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_FieldId", dto.FieldId);
                    command.Parameters.AddWithValue("@p_IsRequired", dto.IsRequired);
                    command.Parameters.AddWithValue("@p_lastUpdatedOn", DateTime.Now);
                    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;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates basic validation step.
        /// </summary>
        /// <param name="data">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 UpdateBasicValidationStep(BasicValidationStepDto data)
        {
            if (data == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "data"));

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                const string CommandText =
                    @"
                    UPDATE [ValidationStep]
                    SET [IsRequired] = @p_IsRequired,
                        [LastUpdatedOn] = @p_lastUpdatedOn
                    WHERE id = @p_id";

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_Id", data.Id);
                    command.Parameters.AddWithValue("@p_IsRequired", data.IsRequired);
                    command.Parameters.AddWithValue("@p_lastUpdatedOn", DateTime.Now);

                    var rowsAffetcted = command.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }