public questStatus Read(LookupId lookupId, out LookupEditorViewModel lookupEditorViewModel)
        {
            // Initialize
            questStatus status = null;

            lookupEditorViewModel = null;


            // Read
            Quest.Functional.MasterPricing.Lookup lookup = null;
            LookupsMgr lookupsMgr = new LookupsMgr(this.UserSession);

            status = lookupsMgr.Read(lookupId, out lookup);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer model.
            lookupEditorViewModel = new LookupEditorViewModel(this.UserSession);
            BufferMgr.TransferBuffer(lookup, lookupEditorViewModel);



            return(new questStatus(Severity.Success));
        }
        public questStatus Delete(LookupId lookupId)
        {
            // Initialize
            questStatus status = null;


            // Delete
            LookupsMgr lookupsMgr = new LookupsMgr(this.UserSession);

            status = lookupsMgr.Delete(lookupId);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus ListLookups(DatabaseId databaseId, out List <BootstrapTreenodeViewModel> lookupNodeList)
        {
            // Initialize
            questStatus status = null;

            lookupNodeList = null;


            // Set up query options.
            // TEMPORARY: OPTIMIZE THIS
            QueryOptions       queryOptions    = new QueryOptions();
            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;


            // Read lookups
            LookupsMgr    lookupsMgr    = new LookupsMgr(this.UserSession);
            QueryResponse queryResponse = null;
            List <Lookup> lookupList    = null;

            status = lookupsMgr.List(queryOptions, out lookupList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Transfer model.
            lookupNodeList = new List <BootstrapTreenodeViewModel>();
            foreach (Lookup lookup in lookupList)
            {
                BootstrapTreenodeViewModel lookupNode = null;
                FormatBootstrapTreeviewNode(lookup, out lookupNode);
                lookupNodeList.Add(lookupNode);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus List(QueryOptions queryOptions, out LookupsListViewModel lookupsListViewModel)
        {
            // Initialize
            questStatus status = null;

            lookupsListViewModel = null;


            // List
            QueryResponse queryResponse = null;
            List <Quest.Functional.MasterPricing.Lookup> lookupList = null;
            LookupsMgr lookupsMgr = new LookupsMgr(this.UserSession);

            status = lookupsMgr.List(queryOptions, out lookupList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Sort
            lookupList.Sort(delegate(Quest.Functional.MasterPricing.Lookup i1, Quest.Functional.MasterPricing.Lookup i2) { return(i1.Name.CompareTo(i2.Name)); });


            // Transfer model.
            // TODO: USE BaseListModeler to xfer queryOptions to QueryOptionsViewModel.
            lookupsListViewModel = new LookupsListViewModel(this.UserSession);
            QueryResponseViewModel queryResponseViewModel = null;

            status = TransferQueryResponse(queryResponse, out queryResponseViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            lookupsListViewModel.QueryResponse = queryResponseViewModel;
            foreach (Quest.Functional.MasterPricing.Lookup lookup in lookupList)
            {
                LookupLineItemViewModel lookupLineItemViewModel = new LookupLineItemViewModel();
                BufferMgr.TransferBuffer(lookup, lookupLineItemViewModel);
                lookupsListViewModel.Items.Add(lookupLineItemViewModel);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus Page(out LookupsListViewModel lookupsListViewModel)
        {
            // Initialize
            questStatus status = null;

            lookupsListViewModel = null;


            // Set up query options.
            // TEMPORARY: OPTIMIZE THIS
            List <SearchField> searchFieldList = new List <SearchField>();

            SearchOptions searchOptions = new SearchOptions();

            searchOptions.SearchFieldList = searchFieldList;

            QueryOptions queryOptions = new QueryOptions(100, 1);

            queryOptions.SearchOptions = searchOptions;
            QueryResponse queryResponse = null;


            // List
            List <Quest.Functional.MasterPricing.Lookup> lookupList = null;
            LookupsMgr lookupsMgr = new LookupsMgr(this.UserSession);

            status = lookupsMgr.List(queryOptions, out lookupList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer model.
            lookupsListViewModel = new LookupsListViewModel(this.UserSession);
            foreach (Quest.Functional.MasterPricing.Lookup lookup in lookupList)
            {
                LookupLineItemViewModel lookupLineItemViewModel = new LookupLineItemViewModel();
                BufferMgr.TransferBuffer(lookup, lookupLineItemViewModel);
                lookupsListViewModel.Items.Add(lookupLineItemViewModel);
            }
            return(new questStatus(Severity.Success));
        }
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/

        #region CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        // CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        public questStatus Save(LookupEditorViewModel lookupEditorViewModel)
        {
            // Initialize
            questStatus status = null;


            // Transfer model
            Quest.Functional.MasterPricing.Lookup lookup = new Functional.MasterPricing.Lookup();
            BufferMgr.TransferBuffer(lookupEditorViewModel, lookup);


            // Determine if this is a create or update
            LookupsMgr lookupsMgr = new LookupsMgr(this.UserSession);

            if (lookupEditorViewModel.Id < BaseId.VALID_ID)
            {
                // Create
                LookupId lookupId = null;
                status = lookupsMgr.Create(lookup, out lookupId);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, lookupEditorViewModel);
                    return(status);
                }
                lookupEditorViewModel.Id = lookupId.Id;
            }
            else
            {
                // Update
                status = lookupsMgr.Update(lookup);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, lookupEditorViewModel);
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }