/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ #region LIST //---------------------------------------------------------------------------------------------------------------------------------- // LIST //---------------------------------------------------------------------------------------------------------------------------------- public questStatus List(DatabaseId databaseId, out ViewsListViewModel viewsListViewModel) { // Initialize questStatus status = null; viewsListViewModel = null; // Get query options from query string QueryOptions queryOptions = null; BaseListModeler baseListModeler = new BaseListModeler(this.HttpRequestBase, new UserSession()); status = baseListModeler.ParsePagingOptions(this.HttpRequestBase, out queryOptions); if (!questStatusDef.IsSuccess(status)) { return(status); } // Set up query options. // TEMPORARY: OPTIMIZE THIS List <SearchField> searchFieldList = new List <SearchField>(); SearchField searchField = new SearchField(); searchField.Name = "DatabaseId"; searchField.SearchOperation = SearchOperation.Equal; searchField.Type = typeof(int); searchField.Value = databaseId.Id.ToString(); searchFieldList.Add(searchField); SearchOptions searchOptions = new SearchOptions(); searchOptions.SearchFieldList = searchFieldList; queryOptions.SearchOptions = searchOptions; QueryResponse queryResponse = null; // Get Database viewsets List <View> viewsetList = null; ViewsMgr viewsMgr = new ViewsMgr(this.UserSession); status = viewsMgr.List(queryOptions, out viewsetList, out queryResponse); if (!questStatusDef.IsSuccess(status)) { return(status); } // Sort by name viewsetList.Sort(delegate(View i1, View i2) { return(i1.Name.CompareTo(i2.Name)); }); // Transfer model. // TODO: USE BaseListModeler to xfer queryOptions to QueryOptionsViewModel. viewsListViewModel = new ViewsListViewModel(this.UserSession); QueryResponseViewModel queryResponseViewModel = null; status = TransferQueryResponse(queryResponse, out queryResponseViewModel); if (!questStatusDef.IsSuccess(status)) { return(status); } viewsListViewModel.QueryResponse = queryResponseViewModel; foreach (Quest.Functional.MasterPricing.View view in viewsetList) { ViewLineItemViewModel viewLineItemViewModel = new ViewLineItemViewModel(); BufferMgr.TransferBuffer(view, viewLineItemViewModel); viewsListViewModel.Items.Add(viewLineItemViewModel); } return(new questStatus(Severity.Success)); }
/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ #region LIST //---------------------------------------------------------------------------------------------------------------------------------- // LIST //---------------------------------------------------------------------------------------------------------------------------------- public questStatus List(ColumnListViewModel viewModel, out ColumnListViewModel columnListViewModel) { // Initialize questStatus status = null; columnListViewModel = null; // Read the database DatabaseId databaseId = new DatabaseId(viewModel.DatabaseId); DatabaseBaseViewModel databaseBaseViewModel = null; DatabaseBaseModeler databaseBaseModeler = new DatabaseBaseModeler(this.HttpRequestBase, this.UserSession); status = databaseBaseModeler.GetDatabase(databaseId, out databaseBaseViewModel); if (!questStatusDef.IsSuccess(status)) { return(status); } // Get columns according to parent entity type ColumnsMgr columnsMgr = new ColumnsMgr(this.UserSession); List <Column> columnList = null; Table table = null; View view = null; if (String.Equals(viewModel.ParentEntityType, "table", StringComparison.InvariantCultureIgnoreCase)) { // Get table columns TableId tableId = new TableId(viewModel.Id); status = columnsMgr.Read(tableId, out columnList); if (!questStatusDef.IsSuccess(status)) { return(status); } // Read the table info TablesMgr tablesMgr = new TablesMgr(this.UserSession); status = tablesMgr.Read(tableId, out table); if (!questStatusDef.IsSuccess(status)) { return(status); } } else if (String.Equals(viewModel.ParentEntityType, "view", StringComparison.InvariantCultureIgnoreCase)) { // Get view columns ViewId viewId = new ViewId(viewModel.Id); status = columnsMgr.Read(viewId, out columnList); if (!questStatusDef.IsSuccess(status)) { return(status); } // Read the view info ViewsMgr viewsMgr = new ViewsMgr(this.UserSession); status = viewsMgr.Read(viewId, out view); if (!questStatusDef.IsSuccess(status)) { return(status); } } else { return(new questStatus(Severity.Error, String.Format("Invalid ParentEntityType: {0}", viewModel.ParentEntityType))); } // Sort by display order columnList.Sort(delegate(Column i1, Column i2) { return(i1.DisplayOrder.CompareTo(i2.DisplayOrder)); }); // Transfer model. columnListViewModel = new ColumnListViewModel(this.UserSession, viewModel); columnListViewModel.DatabaseId = databaseId.Id; columnListViewModel.Database = databaseBaseViewModel; columnListViewModel.Id = viewModel.Id; columnListViewModel.ParentEntityType = viewModel.ParentEntityType; if (table != null) { TableViewModel tableViewModel = new TableViewModel(); BufferMgr.TransferBuffer(table, tableViewModel); columnListViewModel.Table = tableViewModel; } if (view != null) { ViewViewModel viewViewModel = new ViewViewModel(); BufferMgr.TransferBuffer(view, viewViewModel); columnListViewModel.View = viewViewModel; } foreach (Column column in columnList) { ColumnLineItemViewModel columnLineItemViewModel = new ColumnLineItemViewModel(); BufferMgr.TransferBuffer(column, columnLineItemViewModel); columnListViewModel.Items.Add(columnLineItemViewModel); } return(new questStatus(Severity.Success)); }