public ActionResult ExportRun(FilterRunViewModel viewModel)
        {
            questStatus status = null;

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Log Operation
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = LogOperation();
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Authorize
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = Authorize(viewModel._ctx);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Perform operation.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            FilterRunViewModel filterRunViewModel = null;
            ResultsSet         resultsSet         = null;
            FilterPanelModeler filterPanelModeler = new FilterPanelModeler(Request, this.UserSession, viewModel);

            status = filterPanelModeler.Run(viewModel, out filterRunViewModel, out resultsSet);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Return result view model or as Excel
            *---------------------------------------------------------------------------------------------------------------------------------*/
            Response.ClearContent();
            Response.AddHeader("content-disposition", "atachment;filename=" + filterRunViewModel.Name.Replace(" ", "_") + ".xls");
            Response.AddHeader("Content-Type", "application/vnd.ms-excel");
            WriteTsv(resultsSet, Response.Output);
            Response.Flush();
            Response.End();
            return(new EmptyResult());
        }
        public ActionResult Run(FilterEditorViewModel viewModel)
        {
            questStatus status = null;

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Log Operation
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = LogOperation();
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Authorize
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = Authorize(viewModel._ctx);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Perform operation.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            RunFilterRequest runFilterRequest = new RunFilterRequest();

            runFilterRequest.FilterId.Id = viewModel.FilterId;
            runFilterRequest.RowLimit    = viewModel._ResultsOptions.RowLimit;
            runFilterRequest.ColLimit    = viewModel._ResultsOptions.ColLimit;
            FilterRunViewModel filterRunViewModel = null;
            FilterPanelModeler filterPanelModeler = new FilterPanelModeler(Request, this.UserSession, viewModel);

            status = filterPanelModeler.Run(runFilterRequest, out filterRunViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Return result.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = new questStatus(Severity.Success, "Filter successfully run");
            filterRunViewModel.questStatus = status;
            return(Json(filterRunViewModel, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Copy(FilterCopyViewModel viewModel)
        {
            questStatus status = null;

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Log Operation
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = LogOperation();
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Authorize
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = Authorize(viewModel._ctx);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Perform operation.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            FilterCopyViewModel filterCopyViewModel = null;
            FilterPanelModeler  filterPanelModeler  = new FilterPanelModeler(Request, this.UserSession, viewModel);

            status = filterPanelModeler.Copy(viewModel, out filterCopyViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Return result.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = new questStatus(Severity.Success, "Filter successfully copied.  Click on the tableset again to load it.");
            filterCopyViewModel.questStatus = status;
            return(Json(filterCopyViewModel, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Run(FilterRunViewModel viewModel)
        {
            questStatus status = null;

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Log Operation
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = LogOperation();
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Authorize
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = Authorize(viewModel._ctx);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Perform operation.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            if (viewModel.Items.Count == 0)
            {
                string items = Request.Form["Items"].ToString();
                JavaScriptSerializer       javaScriptSerializer = new JavaScriptSerializer();
                List <FilterItemViewModel> itemsList            = javaScriptSerializer.Deserialize <List <FilterItemViewModel> >(items);
                viewModel.Items = itemsList;


                string resultsOptions = Request.Form["_ResultsOptions"].ToString();
                ResultsOptionsViewModel _ResultsOptions = javaScriptSerializer.Deserialize <ResultsOptionsViewModel>(resultsOptions);
                viewModel._ResultsOptions = _ResultsOptions;
            }
            FilterRunViewModel filterRunViewModel = null;
            ResultsSet         resultsSet         = null;
            FilterPanelModeler filterPanelModeler = new FilterPanelModeler(Request, this.UserSession, viewModel);

            status = filterPanelModeler.Run(viewModel, out filterRunViewModel, out resultsSet);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Return result view model or as Excel
            *---------------------------------------------------------------------------------------------------------------------------------*/
            if (viewModel.bExportToExcel)
            {
                Response.ClearContent();
                Response.AddHeader("content-disposition", "atachment;filename=" + filterRunViewModel.Name.Replace(" ", "_") + ".xls");
                Response.AddHeader("Content-Type", "application/vnd.ms-excel");
                WriteTsv(resultsSet, Response.Output);
                Response.Flush();
                Response.End();
                return(new EmptyResult());
            }
            else
            {
                status = new questStatus(Severity.Success, "Filter successfully run");
                filterRunViewModel.questStatus = status;
                return(Json(filterRunViewModel, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Save(FilterPanelViewModel viewModel)
        {
            questStatus          status = null;
            JavaScriptSerializer javaScriptSerializer = null;


            /*----------------------------------------------------------------------------------------------------------------------------------
            * Log Operation
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = LogOperation();
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Authorize
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = Authorize(viewModel._ctx);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Perform operation.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            bool bHaveEditor = false;

            if (viewModel.Entities.Count == 0)
            {
                if (Request.Form["Entities"] != null)
                {
                    string entities = Request.Form["Entities"].ToString();
                    javaScriptSerializer = javaScriptSerializer != null ? javaScriptSerializer : new JavaScriptSerializer();
                    List <BootstrapTreenodeViewModel> entitiesList = javaScriptSerializer.Deserialize <List <BootstrapTreenodeViewModel> >(entities);
                    viewModel.Entities = entitiesList;
                }
                if (Request.Form["Editor"] != null)
                {
                    string editor = Request.Form["Editor"].ToString();
                    javaScriptSerializer = javaScriptSerializer != null ? javaScriptSerializer : new JavaScriptSerializer();
                    FilterEditorViewModel _editor = javaScriptSerializer.Deserialize <FilterEditorViewModel>(editor);
                    viewModel.Editor = _editor;

                    bHaveEditor = true;
                }
            }
            if (viewModel.Items.Count == 0)
            {
                if (Request.Form["Items"] != null)
                {
                    string items = Request.Form["Items"].ToString();
                    javaScriptSerializer = javaScriptSerializer != null ? javaScriptSerializer : new JavaScriptSerializer();
                    List <FilterItemViewModel> itemsList = javaScriptSerializer.Deserialize <List <FilterItemViewModel> >(items);
                    viewModel.Items = itemsList;
                }
                if (Request.Form["Editor"] != null)
                {
                    if (!bHaveEditor)
                    {
                        string editor = Request.Form["Editor"].ToString();
                        javaScriptSerializer = javaScriptSerializer != null ? javaScriptSerializer : new JavaScriptSerializer();
                        FilterEditorViewModel _editor = javaScriptSerializer.Deserialize <FilterEditorViewModel>(editor);
                        viewModel.Editor = _editor;
                    }
                }
            }
            FilterPanelModeler filterPanelModeler = new FilterPanelModeler(Request, this.UserSession, viewModel);

            status = filterPanelModeler.Save(viewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                viewModel.questStatus = status;
                return(Json(viewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Return result.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = new questStatus(Severity.Success, "Filter saved");
            viewModel.questStatus = status;
            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }