Example #1
0
        /// <summary>ArchiveChildrens a User record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">the version number of this row.</param>
        /// <param name="userId">The value for the UserId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int userId)
        {
            // Accessor for the User Table.
            ServerDataModel.UserDataTable userTable = ServerDataModel.User;
            // This record can be used to iterate through all the children.
            ServerDataModel.UserRow userRow = userTable.FindByUserId(userId);
            // Archive the child records.
            for (int index = 0; (index < userRow.GetAllocationRowsByFKUserAllocationCreatedUserId().Length); index = (index + 1))
            {
                ServerDataModel.AllocationRow childAllocationRow = userRow.GetAllocationRowsByFKUserAllocationCreatedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetAllocationRowsByFKUserAllocationModifiedUserId().Length); index = (index + 1))
            {
                ServerDataModel.AllocationRow childAllocationRow = userRow.GetAllocationRowsByFKUserAllocationModifiedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByFKUserExecutionCreatedUserId().Length); index = (index + 1))
            {
                ServerDataModel.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByFKUserExecutionCreatedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByFKUserExecutionModifiedUserId().Length); index = (index + 1))
            {
                ServerDataModel.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByFKUserExecutionModifiedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetPlacementRowsByFKUserPlacementCreatedUserId().Length); index = (index + 1))
            {
                ServerDataModel.PlacementRow childPlacementRow = userRow.GetPlacementRowsByFKUserPlacementCreatedUserId()[index];
                Placement.Archive(adoTransaction, sqlTransaction, childPlacementRow.RowVersion, childPlacementRow.PlacementId);
            }
            for (int index = 0; (index < userRow.GetPlacementRowsByFKUserPlacementModifiedUserId().Length); index = (index + 1))
            {
                ServerDataModel.PlacementRow childPlacementRow = userRow.GetPlacementRowsByFKUserPlacementModifiedUserId()[index];
                Placement.Archive(adoTransaction, sqlTransaction, childPlacementRow.RowVersion, childPlacementRow.PlacementId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            userRow[userTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(userRow);
            userRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"User\" set \"IsArchived\" = 1 where \"UserId\"=@userId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@userId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userId));
            sqlCommand.ExecuteNonQuery();
        }