예제 #1
0
        private questStatus read(MasterPricingEntities dbContext, TablesetColumnId tablesetColumnId, out Quest.Services.Dbio.MasterPricing.TablesetColumns tablesetColumn)
        {
            // Initialize
            questStatus status = null;

            tablesetColumn = null;


            try
            {
                tablesetColumn = dbContext.TablesetColumns.Where(r => r.Id == tablesetColumnId.Id).SingleOrDefault();
                if (tablesetColumn == null)
                {
                    return(new questStatus(Severity.Error, String.Format("ERROR: {0}.{1}: {2}",
                                                                         this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                         String.Format("Id {0} not found", tablesetColumnId.Id))));
                }
            }
            catch (System.Exception ex)
            {
                status = new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                       this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                       ex.InnerException != null ? ex.InnerException.Message : ex.Message));
                LogException(ex, status);
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
예제 #2
0
        public questStatus Delete(DbMgrTransaction trans, TablesetColumnId tablesetColumnId)
        {
            // Initialize
            questStatus status = null;


            // Perform delete in this transaction.
            status = delete((MasterPricingEntities)trans.DbContext, tablesetColumnId);
            if (!questStatusDef.IsSuccess(status))
            {
                RollbackTransaction(trans);
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
예제 #3
0
        public questStatus Delete(TablesetColumnId tablesetColumnId)
        {
            // Initialize
            questStatus status = null;


            // Perform delete.
            using (MasterPricingEntities dbContext = new MasterPricingEntities())
            {
                status = delete(dbContext, tablesetColumnId);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
예제 #4
0
        /*----------------------------------------------------------------------------------------------------------------------------------
        * TablesetColumns
        *---------------------------------------------------------------------------------------------------------------------------------*/
        private questStatus create(MasterPricingEntities dbContext, Quest.Functional.MasterPricing.TablesetColumn tablesetColumn, out TablesetColumnId tablesetColumnId)
        {
            // Initialize
            questStatus status = null;

            tablesetColumnId = null;


            // Perform create
            try
            {
                Quest.Services.Dbio.MasterPricing.TablesetColumns _tablesetColumn = new Quest.Services.Dbio.MasterPricing.TablesetColumns();
                BufferMgr.TransferBuffer(tablesetColumn, _tablesetColumn);
                dbContext.TablesetColumns.Add(_tablesetColumn);
                dbContext.SaveChanges();
                if (_tablesetColumn.Id == 0)
                {
                    return(new questStatus(Severity.Error, "Quest.Functional.MasterPricing.TablesetColumn not created"));
                }
                tablesetColumnId = new TablesetColumnId(_tablesetColumn.Id);
            }
            catch (DbEntityValidationException ex)
            {
                var    errorMessages    = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, fullErrorMessage);

                status = new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                       this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                       exceptionMessage));
                LogException(ex, status);
                return(status);
            }
            catch (System.Exception ex)
            {
                status = new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                       this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                       ex.InnerException != null ? ex.InnerException.Message : ex.Message));
                LogException(ex, status);
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
예제 #5
0
        public questStatus Read(DbMgrTransaction trans, TablesetColumnId tablesetColumnId, out Quest.Functional.MasterPricing.TablesetColumn tablesetColumn)
        {
            // Initialize
            questStatus status = null;

            tablesetColumn = null;


            // Perform read.
            Quest.Services.Dbio.MasterPricing.TablesetColumns _tablesetColumn = null;
            status = read((MasterPricingEntities)trans.DbContext, tablesetColumnId, out _tablesetColumn);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            tablesetColumn = new Quest.Functional.MasterPricing.TablesetColumn();
            BufferMgr.TransferBuffer(_tablesetColumn, tablesetColumn);

            return(new questStatus(Severity.Success));
        }
예제 #6
0
        private questStatus delete(MasterPricingEntities dbContext, TablesetColumnId tablesetColumnId)
        {
            // Initialize
            questStatus status = null;


            try
            {
                // Read the record.
                Quest.Services.Dbio.MasterPricing.TablesetColumns _tablesetColumn = null;
                status = read(dbContext, tablesetColumnId, out _tablesetColumn);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }

                // Delete the record.
                dbContext.TablesetColumns.Remove(_tablesetColumn);
                dbContext.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                var    errorMessages    = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, fullErrorMessage);
                status = new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                       this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                       exceptionMessage));
                LogException(ex, status);
                return(status);
            }
            catch (System.Exception ex)
            {
                status = new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                       this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                       ex.InnerException != null ? ex.InnerException.Message : ex.Message));
                LogException(ex, status);
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
예제 #7
0
        private questStatus getJoinTarget(TablesetColumnId tablesetColumnId, out TablesetTable tablesetTable, out TablesetView tablesetView)
        {
            // Initialize
            questStatus status = null;

            tablesetTable = null;
            tablesetView  = null;


            // Get TablesetColumn
            DbTablesetColumnsMgr dbTablesetColumnsMgr = new DbTablesetColumnsMgr(this.UserSession);
            TablesetColumn       tablesetColumn       = null;

            status = dbTablesetColumnsMgr.Read(tablesetColumnId, out tablesetColumn);
            if (!questStatusDef.IsSuccessOrWarning(status))
            {
                return(status);
            }

            if (tablesetColumn.EntityTypeId == EntityType.Table)
            {
                TablesetTableId     tablesetTableId     = new TablesetTableId(tablesetColumn.TableSetEntityId);
                DbTablesetTablesMgr dbTablesetTablesMgr = new DbTablesetTablesMgr(this.UserSession);
                status = dbTablesetTablesMgr.Read(tablesetTableId, out tablesetTable);
                if (!questStatusDef.IsSuccessOrWarning(status))
                {
                    return(status);
                }
            }
            else if (tablesetColumn.EntityTypeId == EntityType.View)
            {
                TablesetViewId     tablesetViewId     = new TablesetViewId(tablesetColumn.TableSetEntityId);
                DbTablesetViewsMgr dbTablesetViewsMgr = new DbTablesetViewsMgr(this.UserSession);
                status = dbTablesetViewsMgr.Read(tablesetViewId, out tablesetView);
                if (!questStatusDef.IsSuccessOrWarning(status))
                {
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
예제 #8
0
        public questStatus Create(DbMgrTransaction trans, Quest.Functional.MasterPricing.TablesetColumn tablesetColumn, out TablesetColumnId tablesetColumnId)
        {
            // Initialize
            questStatus status = null;

            tablesetColumnId = null;


            // Data rules.


            // Create the tablesetColumn in this transaction.
            status = create((MasterPricingEntities)trans.DbContext, tablesetColumn, out tablesetColumnId);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
예제 #9
0
        /*==================================================================================================================================
        * Properties
        *=================================================================================================================================*/
        #endregion


        #region Public Methods

        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/
        public questStatus Create(Quest.Functional.MasterPricing.TablesetColumn tablesetColumn, out TablesetColumnId tablesetColumnId)
        {
            // Initialize
            questStatus status = null;

            tablesetColumnId = null;


            // Data rules.


            // Create the tablesetColumn
            using (MasterPricingEntities dbContext = new MasterPricingEntities())
            {
                status = create(dbContext, tablesetColumn, out tablesetColumnId);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
예제 #10
0
        public questStatus Save(DbMgrTransaction trans, FilterId filterId, Filter filter)
        {
            // Initialize
            questStatus status    = null;
            Mgr         mgr       = new Mgr(this.UserSession);
            ColumnsMgr  columnMgr = new ColumnsMgr(this.UserSession);


            try
            {
                // Validate filter
                status = Verify(filterId, filter);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }


                // Remove filter entities, items and values.  Also, tables and columns.
                status = _dbFilterMgr.Clear(trans, filterId);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }

                // Save filter tables
                FilterTablesMgr filterTablesMgr = new FilterTablesMgr(this.UserSession);
                foreach (FilterTable filterTable in filter.FilterTableList)
                {
                    filterTable.FilterId = filter.Id;
                    FilterTableId filterTableId = null;
                    status = filterTablesMgr.Create(trans, filterTable, out filterTableId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                    filterTable.Id = filterTableId.Id;
                }

                // Save filter views
                FilterViewsMgr filterViewsMgr = new FilterViewsMgr(this.UserSession);
                foreach (FilterView _filterView in filter.FilterViewList)
                {
                    _filterView.FilterId = filter.Id;
                    FilterViewId filterViewId = null;
                    status = filterViewsMgr.Create(trans, _filterView, out filterViewId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                    _filterView.Id = filterViewId.Id;
                }

                // Save filter columns
                DbFilterMgr      dbFilterMgr      = new DbFilterMgr(this.UserSession);
                FilterColumnsMgr filterColumnsMgr = new FilterColumnsMgr(this.UserSession);
                foreach (FilterColumn filterColumn in filter.FilterColumnList)
                {
                    if (filterColumn.FilterEntityId < BaseId.VALID_ID)
                    {
                        // Get the FilterTable or FilterView Id.
                        // This is a klugie.  Gotta rework DataManager panel first, though.  No time to do that.
                        if (filterColumn.FilterEntityTypeId == FilterEntityType.Table)
                        {
                            TablesetTable tablesetTable = null;
                            status = dbFilterMgr.GetTablesetTable(filterColumn, out tablesetTable);
                            if (!questStatusDef.IsSuccess(status))
                            {
                                return(status);
                            }
                            FilterTable filterTable = filter.FilterTableList.Find(delegate(FilterTable t) { return(t.Schema == tablesetTable.Schema && t.Name == tablesetTable.Name); });
                            if (filterTable == null)
                            {
                                return(new questStatus(Severity.Error, String.Format("ERROR: FilterTable not found for TableSetTable Schema:{0} Name:{1}",
                                                                                     tablesetTable.Schema, tablesetTable.Name)));
                            }
                            filterColumn.FilterEntityId = filterTable.Id;
                        }
                        else if (filterColumn.FilterEntityTypeId == FilterEntityType.View)
                        {
                            TablesetView tablesetView = null;
                            status = dbFilterMgr.GetTablesetView(filterColumn, out tablesetView);
                            if (!questStatusDef.IsSuccess(status))
                            {
                                return(status);
                            }
                            FilterView filterView = filter.FilterViewList.Find(delegate(FilterView v) { return(v.Schema == tablesetView.Schema && v.Name == tablesetView.Name); });
                            if (filterView == null)
                            {
                                return(new questStatus(Severity.Error, String.Format("ERROR: FilterView not found for TableSetTable Schema:{0} Name:{1}",
                                                                                     tablesetView.Schema, tablesetView.Name)));
                            }
                            filterColumn.FilterEntityId = filterView.Id;
                        }
                        else
                        {
                            return(new questStatus(Severity.Error, String.Format("ERROR: FilterColumn FilterEntityTypeId {0} not supported.  FilterColumn {1}",
                                                                                 filterColumn.FilterEntityTypeId, filterColumn.Id)));
                        }
                    }

                    // Save
                    FilterColumnId filterColumnId = null;
                    status = filterColumnsMgr.Create(trans, filterColumn, out filterColumnId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                    filterColumn.Id = filterColumnId.Id;
                }


                // Save filter items.
                FilterItemsMgr      filterItemsMgr      = new FilterItemsMgr(this.UserSession);
                FilterItemJoinsMgr  filterItemJoinsMgr  = new FilterItemJoinsMgr(this.UserSession);
                FilterOperationsMgr filterOperationsMgr = new FilterOperationsMgr(this.UserSession);
                FilterValuesMgr     filterValuesMgr     = new FilterValuesMgr(this.UserSession);
                foreach (FilterItem filterItem in filter.FilterItemList)
                {
                    FilterColumn filterColumn = null;

                    // Get filterItem FilterEntityId
                    if (filterItem.FilterEntityId < BaseId.VALID_ID)
                    {
                        status = dbFilterMgr.GetFilterColumn(filter, filterItem, out filterColumn);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            return(status);
                        }
                        filterItem.FilterEntityId = filterColumn.Id;
                        filterItem.FilterColumn   = filterColumn;      // helps with bookkeeping further down.
                    }

                    // Save FilterItem
                    FilterItemId filterItemId = null;
                    status = filterItemsMgr.Create(trans, filterItem, out filterItemId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                    filterItem.Id = filterItemId.Id;


                    //  Save filter item joins
                    foreach (FilterItemJoin filterItemJoin in filterItem.JoinList)
                    {
                        filterItemJoin.FilterItemId = filterItemId.Id;


                        if (string.IsNullOrEmpty(filterItemJoin.SourceSchema) || string.IsNullOrEmpty(filterItemJoin.SourceEntityName) || string.IsNullOrEmpty(filterItemJoin.SourceColumnName))
                        {
                            // Get join target type (Table or View)
                            TablesetColumnId tablesetColumnId = new TablesetColumnId(filterItemJoin.ColumnId);
                            TablesetTable    tablesetTable    = null;
                            TablesetView     tablesetView     = null;
                            status = getJoinTarget(tablesetColumnId, out tablesetTable, out tablesetView);
                            if (!questStatusDef.IsSuccess(status))
                            {
                                return(status);
                            }
                            filterItemJoin.TargetEntityTypeId = tablesetTable == null ? FilterEntityType.View : FilterEntityType.Table;

                            // Get target identifier parts.
                            string targetSchema     = null;
                            string targetEntityName = null;
                            string targetColumnName = null;
                            SQLIdentifier.ParseThreePartIdentifier(filterItemJoin.Identifier, out targetSchema, out targetEntityName, out targetColumnName);
                            filterItemJoin.TargetSchema     = targetSchema;
                            filterItemJoin.TargetEntityName = targetEntityName;
                            filterItemJoin.TargetColumnName = targetColumnName;


                            // Get source identifier parts.
                            string sourceSchema     = null;
                            string sourceEntityName = null;
                            string sourceColumnName = null;
                            if (filterColumn.FilterEntityTypeId == FilterEntityType.Table)
                            {
                                FilterTable filterTable = filter.FilterTableList.Find(delegate(FilterTable t) { return(filterColumn.FilterEntityId == t.Id); });
                                if (filterTable == null)
                                {
                                    return(new questStatus(Severity.Error, String.Format("ERROR: building Join on {0}, FilterTable {1} not found",
                                                                                         filterItemJoin.Identifier, filterColumn.FilterEntityId)));
                                }
                                sourceSchema     = filterTable.Schema;
                                sourceEntityName = filterTable.Name;
                            }
                            else if (filterColumn.FilterEntityTypeId == FilterEntityType.View)
                            {
                                FilterView filterView = filter.FilterViewList.Find(delegate(FilterView v) { return(filterColumn.FilterEntityId == v.Id); });
                                if (filterView == null)
                                {
                                    return(new questStatus(Severity.Error, String.Format("ERROR: building Join on {0}, FilterView {1} not found",
                                                                                         filterItemJoin.Identifier, filterColumn.FilterEntityId)));
                                }
                                sourceSchema     = filterView.Schema;
                                sourceEntityName = filterView.Name;
                            }
                            sourceColumnName                = filterColumn.Name;
                            filterItemJoin.SourceSchema     = sourceSchema;
                            filterItemJoin.SourceEntityName = sourceEntityName;
                            filterItemJoin.SourceColumnName = sourceColumnName;
                        }

                        // Create FilterItemJoin
                        FilterItemJoinId filterItemJoinId = null;
                        status = filterItemJoinsMgr.Create(trans, filterItemJoin, out filterItemJoinId);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            return(status);
                        }
                    }

                    // Save filter operations
                    foreach (FilterOperation filterOperation in filterItem.OperationList)
                    {
                        filterOperation.FilterItemId = filterItem.Id;

                        FilterOperationId filterOperationId = null;
                        status = filterOperationsMgr.Create(trans, filterOperation, out filterOperationId);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            return(status);
                        }

                        // Save filter values
                        foreach (FilterValue filterValue in filterOperation.ValueList)
                        {
                            filterValue.FilterOperationId = filterOperationId.Id;
                            FilterValueId filterValueId = null;
                            status = filterValuesMgr.Create(trans, filterValue, out filterValueId);
                            if (!questStatusDef.IsSuccess(status))
                            {
                                return(status);
                            }
                        }
                    }
                }

                // Save filter procedures
                //     Get the filter's database.
                Quest.Functional.MasterPricing.Database database = null;
                status = GetFilterDatabase(filterId, out database);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                // NOTE: business rules reads in procedure parameters and writes them.
                FilterProceduresMgr filterProceduresMgr = new FilterProceduresMgr(this.UserSession);
                foreach (FilterProcedure filterProcedure in filter.FilterProcedureList)
                {
                    if (string.IsNullOrEmpty(filterProcedure.Name))
                    {
                        continue;
                    }
                    filterProcedure.FilterId = filter.Id;
                    FilterProcedureId filterProcedureId = null;
                    status = filterProceduresMgr.Create(trans, database, filterProcedure, out filterProcedureId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                }

                // NOTE: YOU STILL HAVE TO UPDATE THE FILTER'S SQL.  BUT, CAN'T HERE, B/C YOU'RE IN A TRANSACTION.
                // TODO: REFACTOR SO YOU CAN, BUT GOTTA GET A PARAMETERS MAKE-REQUIRED UPDATE OUT THERE FIRST.
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
예제 #11
0
        public questStatus GetTablesetView(DatabaseId databaseId, FilterViewTablesetViewId filterViewTablesetViewId, out TablesetView tablesetView)
        {
            // Initialize
            questStatus status = null;

            tablesetView = null;


            // Get tableset view
            DbTablesetViewsMgr dbTablesetViewsMgr = new DbTablesetViewsMgr(this._userSession);

            status = dbTablesetViewsMgr.Read(filterViewTablesetViewId, out tablesetView);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Get tableset columns
            EntityType entityType = new EntityType();

            entityType.Id = EntityType.View;
            TableSetEntityId      tableSetEntityId     = new TableSetEntityId(tablesetView.Id);
            DbTablesetColumnsMgr  dbTablesetColumnsMgr = new DbTablesetColumnsMgr(this._userSession);
            List <TablesetColumn> tablesetColumnList   = null;

            TablesetColumnId tablesetColumnId = new TablesetColumnId();

            status = dbTablesetColumnsMgr.Read(entityType, tableSetEntityId, out tablesetColumnList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            tablesetView.TablesetColumnList = tablesetColumnList;


            // Get view
            View view = null;

            status = GetViewInfo(databaseId, tablesetView, out view);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            tablesetView.View = view;


            // Get column info
            DbColumnsMgr dbColumnsMgr = new DbColumnsMgr(this._userSession);
            EntityTypeId entityTypeId = new EntityTypeId(EntityType.View);
            EntityId     entityId     = new EntityId(view.Id);

            foreach (TablesetColumn tablesetColumn in tablesetColumnList)
            {
                Column column = null;
                status = dbColumnsMgr.Read(entityTypeId, entityId, tablesetColumn.Name, out column);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                tablesetColumn.Column = column;
            }
            return(new questStatus(Severity.Success));
        }
예제 #12
0
        public questStatus SaveTablesetConfiguration(TablesetConfiguration tablesetConfiguration, out TablesetId tablesetId)
        {
            // Initialize
            questStatus status = null;

            tablesetId = null;
            DbMgrTransaction trans           = null;
            bool             bFiltersRemoved = false;
            questStatus      status2         = null;

            try
            {
                // BEGIN TRANSACTION
                status = BeginTransaction("SaveTablesetConfiguration" + Guid.NewGuid().ToString(), out trans);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }


                /*
                 * Update tableset info.
                 */
                // Read the tableset
                TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession);
                TablesetId   _tablesetId  = new TablesetId(tablesetConfiguration.Tableset.Id);
                Tableset     _tableset    = null;
                status = tablesetsMgr.Read(trans, _tablesetId, out _tableset);
                if (!questStatusDef.IsSuccess(status))
                {
                    RollbackTransaction(trans);
                    return(status);
                }


                /*
                 * Remove all tableset entities.
                 */
                status = ClearTablesetEntities(trans, _tablesetId);
                if (!questStatusDef.IsSuccess(status))
                {
                    RollbackTransaction(trans);
                    return(status);
                }


                // TESTING ONLY:  COMMIT TRANSACTION
                bool bKlugie = false;
                if (bKlugie)
                {
                    status = CommitTransaction(trans);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                }


                /*
                 * Get database entites.
                 */
                DatabaseId       databaseId       = new DatabaseId(tablesetConfiguration.Database.Id);
                DatabaseMgr      databaseMgr      = new DatabaseMgr(this.UserSession);
                DatabaseEntities databaseEntities = null;
                status = databaseMgr.ReadDatabaseEntities(databaseId, out databaseEntities);
                if (!questStatusDef.IsSuccess(status))
                {
                    RollbackTransaction(trans);
                    return(status);
                }


                #region Save tableset info.

                /*
                 * Save tableset info.
                 */
                DbTablesetColumnsMgr dbTablesetColumnsMgr = new DbTablesetColumnsMgr(this.UserSession);

                // Save table info.
                DbTablesetTablesMgr  dbTablesetTablesMgr = new DbTablesetTablesMgr(this.UserSession);
                List <TablesetTable> tablesetTableList   = new List <TablesetTable>();
                foreach (TablesetTable tablesetTable in tablesetConfiguration.TablesetTables)
                {
                    Table _table = databaseEntities.TableList.Find(delegate(Table t) { return(t.Schema == tablesetTable.Schema && t.Name == tablesetTable.Name); });
                    if (_table == null)
                    {
                        RollbackTransaction(trans);
                        return(new questStatus(Severity.Error, String.Format("ERROR: tableset table [{0}].[{1}] not found in database metainfo.  Try refreshing database schema info",
                                                                             tablesetTable.Schema, tablesetTable.Name)));
                    }
                    tablesetTable.TablesetId = _tableset.Id;
                    tablesetTable.Table      = _table;
                    tablesetTableList.Add(tablesetTable);


                    // Create tableset table.
                    TablesetTableId tablesetTableId = null;
                    status = dbTablesetTablesMgr.Create(trans, tablesetTable, out tablesetTableId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        RollbackTransaction(trans);
                        return(status);
                    }

                    foreach (Column column in _table.ColumnList)
                    {
                        Column _column = _table.ColumnList.Find(delegate(Column c) { return(c.Name == column.Name); });
                        if (_column == null)
                        {
                            RollbackTransaction(trans);
                            return(new questStatus(Severity.Error, String.Format("ERROR: column [{0}] not found in table [{1}].[{2}] in database metainfo.  Try refreshing database schema info",
                                                                                 column.Name, _table.Schema, _table.Name)));
                        }

                        TablesetColumn tablesetColumn = new TablesetColumn();
                        tablesetColumn.EntityTypeId     = EntityType.Table;
                        tablesetColumn.TableSetEntityId = tablesetTableId.Id;
                        tablesetColumn.Name             = column.Name;

                        TablesetColumnId tablesetColumnId = null;
                        status = dbTablesetColumnsMgr.Create(trans, tablesetColumn, out tablesetColumnId);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            RollbackTransaction(trans);
                            return(status);
                        }
                    }
                }

                // Save view info.
                DbTablesetViewsMgr  dbTablesetViewsMgr = new DbTablesetViewsMgr(this.UserSession);
                List <TablesetView> tablesetViewList   = new List <TablesetView>();
                foreach (TablesetView tablesetView in tablesetConfiguration.TablesetViews)
                {
                    View _view = databaseEntities.ViewList.Find(delegate(View v) { return(v.Schema == tablesetView.Schema && v.Name == tablesetView.Name); });
                    if (_view == null)
                    {
                        RollbackTransaction(trans);
                        return(new questStatus(Severity.Error, String.Format("ERROR: tableset view [{0}].[{1}] not found in database metainfo.  Try refreshing database schema info",
                                                                             tablesetView.Schema, tablesetView.Name)));
                    }
                    tablesetView.TablesetId = _tableset.Id;
                    tablesetView.View       = _view;
                    tablesetViewList.Add(tablesetView);

                    // Create tableset view.
                    TablesetViewId tablesetViewId = null;
                    status = dbTablesetViewsMgr.Create(trans, tablesetView, out tablesetViewId);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        RollbackTransaction(trans);
                        return(status);
                    }

                    foreach (Column column in _view.ColumnList)
                    {
                        Column _column = _view.ColumnList.Find(delegate(Column c) { return(c.Name == column.Name); });
                        if (_column == null)
                        {
                            RollbackTransaction(trans);
                            return(new questStatus(Severity.Error, String.Format("ERROR: column [{0}] not found in view [{1}].[{2}] in database metainfo.  Try refreshing database schema info",
                                                                                 column.Name, _view.Schema, _view.Name)));
                        }

                        TablesetColumn tablesetColumn = new TablesetColumn();
                        tablesetColumn.EntityTypeId     = EntityType.View;
                        tablesetColumn.TableSetEntityId = tablesetViewId.Id;
                        tablesetColumn.Name             = column.Name;

                        TablesetColumnId tablesetColumnId = null;
                        status = dbTablesetColumnsMgr.Create(trans, tablesetColumn, out tablesetColumnId);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            RollbackTransaction(trans);
                            return(status);
                        }
                    }
                }
                #endregion


                // Update tableset.
                bFiltersRemoved      = false;
                _tableset.DatabaseId = tablesetConfiguration.Database.Id;
                status2 = tablesetsMgr.Update(trans, _tableset);
                if (!questStatusDef.IsSuccess(status2))
                {
                    if (questStatusDef.IsWarning(status2))
                    {
                        bFiltersRemoved = true;
                    }
                    else
                    {
                        RollbackTransaction(trans);
                        return(status);
                    }
                }


                // COMMIT TRANSACTION
                status = CommitTransaction(trans);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }

                // Return the tableset id
                tablesetId = new TablesetId(tablesetConfiguration.Tableset.Id);
            }
            catch (System.Exception ex)
            {
                if (trans != null)
                {
                    RollbackTransaction(trans);
                }
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            if (bFiltersRemoved)
            {
                return(status2);
            }
            return(new questStatus(Severity.Success));
        }