public questStatus List(ParameterListViewModel viewModel, out ParameterListViewModel parameterListViewModel)
        {
            // Initialize
            questStatus status = null;

            parameterListViewModel = null;


            // Get stored procedure parameters
            StoredProcedureId storedProcedureId = new StoredProcedureId(viewModel.StoredProcedureId);
            List <StoredProcedureParameter> storedProcedureParameterList = null;
            StoredProcedureParametersMgr    storedProcedureParametersMgr = new StoredProcedureParametersMgr(this.UserSession);

            status = storedProcedureParametersMgr.Read(storedProcedureId, out storedProcedureParameterList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Sort by display order
            // NOTE: ORDER IN DATABASE -SHOULD- BE ORDER IN SPROC.


            // Transfer model.
            parameterListViewModel = new ParameterListViewModel(this.UserSession, viewModel);
            parameterListViewModel.StoredProcedureId = viewModel.StoredProcedureId;
            foreach (StoredProcedureParameter storedProcedureParameter in storedProcedureParameterList)
            {
                ParameterLineItemViewModel parameterLineItemViewModel = new ParameterLineItemViewModel();
                BufferMgr.TransferBuffer(storedProcedureParameter, parameterLineItemViewModel);
                parameterLineItemViewModel.bRequired = storedProcedureParameter.bRequired ? "Yes" : "No";
                parameterListViewModel.Items.Add(parameterLineItemViewModel);
            }
            return(new questStatus(Severity.Success));
        }
Exemple #2
0
        public new questStatus GetStoredProdecureParameters(Quest.Functional.MasterPricing.Database database, string filterProcedureName, out List <FilterProcedureParameter> filterProcedureParameterList)
        {
            // Initialize
            questStatus status = null;

            filterProcedureParameterList = null;


            // Get stored procedure
            DatabaseId          databaseId          = new DatabaseId(database.Id);
            StoredProcedure     storedProcedure     = null;
            StoredProceduresMgr storedProceduresMgr = new StoredProceduresMgr(this.UserSession);

            status = storedProceduresMgr.Read(databaseId, filterProcedureName, out storedProcedure);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Get stored procedure parameters
            StoredProcedureId storedProcedureId = new StoredProcedureId(storedProcedure.Id);
            List <StoredProcedureParameter> storedProcedureParameterList = null;
            StoredProcedureParametersMgr    storedProcedureParametersMgr = new StoredProcedureParametersMgr(this.UserSession);

            storedProcedureParametersMgr.Read(storedProcedureId, out storedProcedureParameterList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer over to filter procedure.
            filterProcedureParameterList = new List <FilterProcedureParameter>();
            foreach (StoredProcedureParameter storedProcedureParameter in storedProcedureParameterList)
            {
                FilterProcedureParameter filterProcedureParameter = new FilterProcedureParameter();
                BufferMgr.TransferBuffer(storedProcedureParameter, filterProcedureParameter);
                filterProcedureParameterList.Add(filterProcedureParameter);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus MakeRequired(MakeRequiredViewModel makeRequiredViewModel)
        {
            // Initialize
            questStatus      status = null;
            Mgr              mgr    = new Mgr(this.UserSession);
            DbMgrTransaction trans  = null;


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


            // Update every parameter as required or not.
            StoredProcedureParametersMgr storedProcedureParametersMgr = new StoredProcedureParametersMgr(this.UserSession);

            foreach (BaseId baseId in makeRequiredViewModel.Items)
            {
                // Get the parameter
                StoredProcedureParameterId storedProcedureParameterId = new StoredProcedureParameterId(baseId.Id);
                StoredProcedureParameter   storedProcedureParameter   = null;
                status = storedProcedureParametersMgr.Read(trans, storedProcedureParameterId, out storedProcedureParameter);
                if (!questStatusDef.IsSuccess(status))
                {
                    mgr.RollbackTransaction(trans);
                    return(status);
                }

                // Make sure same stored procedure
                if (makeRequiredViewModel.StoredProcedureId != storedProcedureParameter.StoredProcedureId)
                {
                    mgr.RollbackTransaction(trans);
                    return(new questStatus(Severity.Error, "All parameter Id's must be from the same stored procedure!"));
                }

                // Set required flag accordingly and update.
                storedProcedureParameter.bRequired = true;
                status = storedProcedureParametersMgr.Update(trans, storedProcedureParameter);
                if (!questStatusDef.IsSuccess(status))
                {
                    mgr.RollbackTransaction(trans);
                    return(status);
                }
            }

            // Set all the OTHER parameters to false
            List <StoredProcedureParameter> storedProcedureParameterList = null;
            StoredProcedureId storedProcedureId = new StoredProcedureId(makeRequiredViewModel.StoredProcedureId);

            status = storedProcedureParametersMgr.Read(trans, storedProcedureId, out storedProcedureParameterList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            foreach (StoredProcedureParameter storedProcedureParameter in storedProcedureParameterList)
            {
                BaseId baseId = makeRequiredViewModel.Items.Find(delegate(BaseId _baseId) { return(_baseId.Id == storedProcedureParameter.Id); });
                if (baseId == null)
                {
                    storedProcedureParameter.bRequired = false;
                    status = storedProcedureParametersMgr.Update(trans, storedProcedureParameter);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        mgr.RollbackTransaction(trans);
                        return(status);
                    }
                }
            }

            // COMMIT TRANSACTION
            // THIS HAS TO BE COMMITTED HERE TO AVOID DEADLOCKING ON UPDATING THE FILTERS, NEXT.
            status = mgr.CommitTransaction(trans);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

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


            ////// Refresh filters using this sproc.
            ////List<Quest.Functional.MasterPricing.FilterId> updatedFilterIds = null;
            ////StoredProceduresMgr storedProceduresMgr = new StoredProceduresMgr(this.UserSession);
            ////status = storedProceduresMgr.RefreshFilters(storedProcedureId, out updatedFilterIds);
            ////if (!questStatusDef.IsSuccess(status))
            ////{
            ////    mgr.RollbackTransaction(trans);
            ////    return (status);
            ////}


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


            ////// TODO: REFACTOR TO GET ALL-IN-ONE TRANSACTION
            ////foreach (FilterId filterId in updatedFilterIds)
            ////{
            ////    Quest.Functional.MasterPricing.Filter filterWithSQL = null;
            ////    FilterMgr filterMgr = new FilterMgr(this.UserSession);
            ////    status = filterMgr.GenerateFilterSQL(filterId, out filterWithSQL);
            ////    if (!questStatusDef.IsSuccess(status))
            ////    {
            ////        return (status);
            ////    }

            ////    // Update filter
            ////    FiltersMgr filtersMgr = new FiltersMgr(this.UserSession);
            ////    status = filtersMgr.Update(filterWithSQL);
            ////    if (!questStatusDef.IsSuccess(status))
            ////    {
            ////        return (status);
            ////    }
            ////}

            return(new questStatus(Severity.Success));
        }