/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ public questStatus Save(FilterEditorViewModel filterEditorViewModel) { // Initialize questStatus status = null; // Validate if (filterEditorViewModel.TablesetId < BaseId.VALID_ID) { return(new questStatus(Severity.Error, "Invalid Tableset Id")); } // Transfer model Quest.Functional.MasterPricing.Filter filter = new Functional.MasterPricing.Filter(); BufferMgr.TransferBuffer(filterEditorViewModel, filter); // Determine if this is a create or update FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); if (filterEditorViewModel.Id < BaseId.VALID_ID) { // Create FilterId filterId = null; status = filtersMgr.Create(filter, out filterId); if (!questStatusDef.IsSuccess(status)) { FormatErrorMessage(status, filterEditorViewModel); return(status); } filterEditorViewModel.Id = filterId.Id; } else { // Update status = filtersMgr.Update(filter); if (!questStatusDef.IsSuccess(status)) { FormatErrorMessage(status, filterEditorViewModel); return(status); } } return(new questStatus(Severity.Success)); }
//---------------------------------------------------------------------------------------------------------------------------------- // Transfers //---------------------------------------------------------------------------------------------------------------------------------- public questStatus MergeFilterEditorViewModel(FilterRunViewModel filterRunViewModel, Quest.Functional.MasterPricing.Filter filterFROMDatabase, out Quest.Functional.MasterPricing.Filter filter) { // Initialize filter = filterFROMDatabase; // Copy over general stuff. filter = new Functional.MasterPricing.Filter(); filter.Id = filterFROMDatabase.Id; filter.TablesetId = filterFROMDatabase.TablesetId; filter.Name = filterFROMDatabase.Name; filter.Summary = filterFROMDatabase.Summary; filter.FilterTableList = filterFROMDatabase.FilterTableList; filter.FilterViewList = filterFROMDatabase.FilterViewList; filter.FilterColumnList = filterFROMDatabase.FilterColumnList; filter.FilterItemList = new List <FilterItem>(); // Whatever items are sent in is what we're running. filter.FilterProcedureList = filterFROMDatabase.FilterProcedureList; // // Filter Items - *accumualte* given filter items to the database operations. // if (filterRunViewModel.Items == null) { filter.FilterItemList = filterFROMDatabase.FilterItemList; } else { foreach (FilterItemViewModel filterItemViewModel in filterRunViewModel.Items) { // Get the FilterItem from the database copy of the filter. FilterItem filterItem = filterFROMDatabase.FilterItemList.Find(delegate(FilterItem fi) { return(filterItemViewModel.Name == fi.FilterColumn.Name && filterItemViewModel.ParentEntity.type == fi.FilterColumn.ParentEntityType.type && filterItemViewModel.ParentEntity.Schema == fi.FilterColumn.ParentEntityType.Schema && filterItemViewModel.ParentEntity.Name == fi.FilterColumn.ParentEntityType.Name); }); if (filterItem == null) { return(new questStatus(Severity.Error, String.Format("ERROR: Item {0} [{1}].[{2}] not found in filter", filterItemViewModel.ParentEntity.type, filterItemViewModel.ParentEntity.Schema, filterItemViewModel.ParentEntity.Name))); } // Accumulate any operations given to the operations already on the filter. foreach (FilterOperationViewModel filterOperationViewModel in filterItemViewModel.Operations) { FilterOperation filterOperation = new FilterOperation(); filterOperation.FilterOperatorId = filterOperationViewModel.Operator; foreach (FilterValueViewModel filterValueViewModel in filterOperationViewModel.Values) { FilterValue filterValue = new FilterValue(); filterValue.Value = filterValueViewModel.Value; filterOperation.ValueList.Add(filterValue); } filterItem.OperationList.Add(filterOperation); } // Add this item to the filter. filter.FilterItemList.Add(filterItem); } } return(new questStatus(Severity.Success)); }
/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ public questStatus Save(FilterPanelViewModel filterPanelViewModel) { // Initialize questStatus status = null; Quest.Functional.MasterPricing.Filter filter = null; FilterId filterId = null; // Validate if (filterPanelViewModel.Editor.TablesetId < BaseId.VALID_ID) { return(new questStatus(Severity.Error, "Invalid Tableset Id")); } if (filterPanelViewModel.Editor.FilterId < BaseId.VALID_ID) { // For headless agents that want to save all-in-one, not via the Filters panel. filter = new Functional.MasterPricing.Filter(); BufferMgr.TransferBuffer(filterPanelViewModel.Editor, filter); filterId = null; FiltersMgr filtersMgr = new FiltersMgr(this.UserSession); status = filtersMgr.Create(filter, out filterId); if (!questStatusDef.IsSuccess(status)) { return(status); } filterPanelViewModel.Editor.Id = filterId.Id; filterPanelViewModel.Editor.FilterId = filterId.Id; } // Read tableset configuration TablesetId tablesetId = new TablesetId(filterPanelViewModel.Editor.TablesetId); TablesetDataManagement tablesetDataManagement = null; TablesetMgr tablesetMgr = new TablesetMgr(this.UserSession); status = tablesetMgr.ReadTablesetDataManagement(tablesetId, out tablesetDataManagement); if (!questStatusDef.IsSuccess(status)) { return(status); } #region Transfer filter entities // // Transfer filter entities // filter = new Functional.MasterPricing.Filter(); filter.TablesetId = filterPanelViewModel.Editor.TablesetId; filter.Id = filterPanelViewModel.Editor.Id; foreach (BootstrapTreenodeViewModel filterEntity in filterPanelViewModel.Entities) { if (filterEntity.type == "table") { FilterTable filterTable = new FilterTable(); filterTable.FilterId = filterPanelViewModel.Editor.Id; filterTable.Schema = filterEntity.Schema; filterTable.Name = filterEntity.Name; filter.FilterTableList.Add(filterTable); } else if (filterEntity.type == "view") { FilterView filterView = new FilterView(); filterView.FilterId = filterPanelViewModel.Editor.Id; filterView.Schema = filterEntity.Schema; filterView.Name = filterEntity.Name; filter.FilterViewList.Add(filterView); } else if (filterEntity.type == "column") { FilterColumn filterColumn = new FilterColumn(); filterColumn.FilterId = filterPanelViewModel.Editor.Id; filterColumn.Name = filterEntity.Name; filterColumn.TablesetEntityId = filterEntity.ParentId; if (filterEntity.parentType == "table") { TablesetTable parentTablesetTable = tablesetDataManagement.TablesetConfiguration.TablesetTables.Find(delegate(TablesetTable tt) { return(tt.Id == filterEntity.ParentId); }); if (parentTablesetTable == null) { return(new questStatus(Severity.Error, String.Format("ERROR: column filter entity \"{0}\" (Id {1}) table parent Id {2} not found.", filterEntity.text, filterEntity.Id, filterEntity.ParentId))); } filterColumn.FilterEntityTypeId = FilterEntityType.Table; // If column table not in filter entities, add it. BootstrapTreenodeViewModel filterColumnTable = filterPanelViewModel.Entities.Find(delegate(BootstrapTreenodeViewModel n) { return(n.type == "table" && n.Id == filterEntity.ParentId); }); if (filterColumnTable == null) { FilterTable filterTable = filter.FilterTableList.Find(delegate(FilterTable t) { return(filterEntity.ParentId == t.TablesetTable.Id); }); if (filterTable == null) { filterTable = new FilterTable(); filterTable.FilterId = filterPanelViewModel.Editor.Id; filterTable.TablesetTable = parentTablesetTable; filterTable.Schema = parentTablesetTable.Schema; filterTable.Name = parentTablesetTable.Name; filter.FilterTableList.Add(filterTable); } } } else if (filterEntity.parentType == "view") { TablesetView parentTablesetView = tablesetDataManagement.TablesetConfiguration.TablesetViews.Find(delegate(TablesetView tv) { return(tv.Id == filterEntity.ParentId); }); if (parentTablesetView == null) { return(new questStatus(Severity.Error, String.Format("ERROR: column filter entity \"{0}\" (Id {1}) view parent Id {2} not found.", filterEntity.text, filterEntity.Id, filterEntity.ParentId))); } filterColumn.FilterEntityTypeId = FilterEntityType.View; // If column view not in filter entities, add it. BootstrapTreenodeViewModel filterColumnView = filterPanelViewModel.Entities.Find(delegate(BootstrapTreenodeViewModel n) { return(n.type == "view" && n.Id == filterEntity.ParentId); }); if (filterColumnView == null) { FilterView filterView = filter.FilterViewList.Find(delegate(FilterView v) { return(filterEntity.ParentId == v.TablesetView.Id); }); if (filterView == null) { filterView = new FilterView(); filterView.FilterId = filterPanelViewModel.Editor.Id; filterView.TablesetView = parentTablesetView; filterView.Schema = parentTablesetView.Schema; filterView.Name = parentTablesetView.Name; filter.FilterViewList.Add(filterView); } } } else { return(new questStatus(Severity.Error, String.Format("ERROR: column filter entity \"{0}\" (Id {1}) unknown parent parent type: {2}", filterEntity.text, filterEntity.Id, filterEntity.ParentId, (filterEntity.parentType == null ? "null" : filterEntity.parentType)))); } filter.FilterColumnList.Add(filterColumn); } else { return(new questStatus(Severity.Error, String.Format("Invalid filter entity type: {0}", filterEntity.type))); } } #endregion #region Transfer filter items // // Transfer filter items // foreach (FilterItemViewModel filterItemViewModel in filterPanelViewModel.Items) { // Filter Item FilterItem filterItem = new FilterItem(); filterItem.FilterId = filterPanelViewModel.Editor.FilterId; if (filterItemViewModel.Entity.type == "table") { filterItem.FilterEntityTypeId = FilterEntityType.Table; } if (filterItemViewModel.Entity.type == "view") { filterItem.FilterEntityTypeId = FilterEntityType.View; } else if (filterItemViewModel.Entity.type == "column") { filterItem.FilterEntityTypeId = FilterEntityType.Column; } filterItem.TablesetColumnId = filterItemViewModel.Entity.Id; filterItem.Label = filterItemViewModel.Label; filterItem.ParameterName = filterItemViewModel.ParameterName; filterItem.bHidden = filterItemViewModel.bHidden; filterItem.bBulkUpdateValueRequired = filterItemViewModel.bBulkUpdateValueRequired; // Joins foreach (FilterItemJoinViewModel filterItemJoinViewModel in filterItemViewModel.Joins) { FilterItemJoin filterItemJoin = new FilterItemJoin(); filterItemJoin.ColumnId = filterItemJoinViewModel.ColumnId; filterItemJoin.JoinType = filterItemJoinViewModel.JoinType; filterItemJoin.Identifier = filterItemJoinViewModel.Identifier; filterItem.JoinList.Add(filterItemJoin); } // Operations foreach (FilterOperationViewModel filterOperationViewModel in filterItemViewModel.Operations) { FilterOperation filterOperation = new FilterOperation(); filterOperation.FilterOperatorId = filterOperationViewModel.Operator; // Values foreach (FilterValueViewModel filterValueViewModel in filterOperationViewModel.Values) { FilterValue filterValue = new FilterValue(); filterValue.Value = filterValueViewModel.Value; filterOperation.ValueList.Add(filterValue); } filterItem.OperationList.Add(filterOperation); } // Lookup if (filterItemViewModel.Lookup.Id >= BaseId.VALID_ID) { filterItem.LookupId = filterItemViewModel.Lookup.Id; } // TypeList if (filterItemViewModel.TypeList.Id >= BaseId.VALID_ID) { filterItem.TypeListId = filterItemViewModel.TypeList.Id; } filter.FilterItemList.Add(filterItem); } #endregion #region Transfer filter procedures // // Transfer filter procedures // foreach (FilterProcedureViewModel filterProcedureViewModel in filterPanelViewModel.Procedures) { if (filterProcedureViewModel.Id > BaseId.INVALID_ID) { FilterProcedure filterProcedure = new FilterProcedure(); BufferMgr.TransferBuffer(filterProcedureViewModel, filterProcedure); filterProcedure.FilterId = filterPanelViewModel.Editor.FilterId; filter.FilterProcedureList.Add(filterProcedure); } } #endregion #region Save filter // // Save filter // filterId = new FilterId(filterPanelViewModel.Editor.FilterId); FilterMgr filterMgr = new FilterMgr(this.UserSession); status = filterMgr.Save(filterId, filter); if (!questStatusDef.IsSuccess(status)) { if (questStatusDef.IsWarning(status)) { return(status); } return(new questStatus(status.Severity, String.Format("Error saving filter items: {0}", status.Message))); } #endregion #region Return procedure parameters // // Return procedure parameters // // Get filter database Quest.Functional.MasterPricing.Database database = null; filterMgr.GetFilterDatabase(filterId, out database); if (filter.FilterProcedureList.Count > 0) { foreach (FilterProcedureViewModel filterProcedureViewModel in filterPanelViewModel.Procedures) { if ((filterProcedureViewModel.Id == BaseId.INVALID_ID) || (string.IsNullOrEmpty(filterProcedureViewModel.Name))) { continue; } // Get procedure parameters List <Quest.Functional.MasterPricing.FilterProcedureParameter> filterProcedureParameterList = null; status = filterMgr.GetStoredProdecureParameters(database, filterProcedureViewModel.Name, out filterProcedureParameterList); if (!questStatusDef.IsSuccess(status)) { return(status); } foreach (FilterProcedureParameter filterProcedureParameter in filterProcedureParameterList) { FilterProcedureParameterViewModel filterProcedureParameterViewModel = new FilterProcedureParameterViewModel(); BufferMgr.TransferBuffer(filterProcedureParameter, filterProcedureParameterViewModel, true); filterProcedureParameterViewModel.Precision = filterProcedureParameter.Precision[0]; filterProcedureParameterViewModel.Scale = filterProcedureParameter.Scale[0]; filterProcedureViewModel.Parameters.Add(filterProcedureParameterViewModel); } } } #endregion // Return warning if no items in filter. if (filter.FilterItemList.Count == 0) { return(new questStatus(Severity.Warning, "Filter successfully saved, but has no items")); } return(new questStatus(Severity.Success)); }