public JsonResult ClearAdvSearchFilters()
        {
            IList <PropertyUnitModel> model = new List <PropertyUnitModel>();
            BreadcrumbNavigation      nav   = (BreadcrumbNavigation)System.Web.HttpContext.Current.Session["Navigation"];

            if (nav == null)
            {
                nav = new BreadcrumbNavigation();
            }
            AdvancedSearchResults res = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearchResults").FirstOrDefault() as AdvancedSearchResults;

            if (res != null)
            {
                nav.Pop();
            }

            AdvancedSearchNav adv = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearch").FirstOrDefault() as AdvancedSearchNav;

            adv.PageData = new List <PropertyUnitModel>();
            nav.Push(adv);
            nav.LastNavigable = "AdvancedSearch";


            System.Web.HttpContext.Current.Session["Navigation"] = nav;

            return(Json(ResponseStatus.Success, RenderPartialViewToString("ConditionsContainer", model), JsonRequestBehavior.AllowGet));
        }
        public AdvSearchFiltersAll BreadcrumbNavigationGetSet(AdvSearchFiltersAll filters)
        {
            BreadcrumbNavigation nav = (BreadcrumbNavigation)System.Web.HttpContext.Current.Session["Navigation"];

            if (nav == null)
            {
                nav = new BreadcrumbNavigation();
            }
            if (nav.Contains("Exporter"))
            {
                nav.Pop();
            }
            if (nav.Contains("Comparison"))
            {
                nav.Pop();
            }
            if (nav.Contains("MaterialDetails1"))
            {
                nav.Pop();
            }
            if (nav.Contains("Subgroups"))
            {
                nav.Pop();
            }
            if (nav.Contains("BrowseFacets"))
            {
                nav.Pop();
            }
            if (nav.Contains("BrowseHome"))
            {
                nav.Pop();
            }



            AdvancedSearchNav adv = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearch").FirstOrDefault() as AdvancedSearchNav;

            if (adv == null)
            {
                adv.IsVisible = true;
                adv           = new AdvancedSearchNav();
            }


            IList <PropertyUnitModel> units = new List <PropertyUnitModel>();

            foreach (var item in nav.GetOrderedItems().Where(n => n.NavigableID != "HomePage" && n.NavigableID != "AdvancedSearch"))
            {
                item.IsVisible = false;
            }
            if (nav.Contains("FullSearch"))
            {
                FullSearch fs = nav.GetOrderedItems().Where(n => n.NavigableID == "FullSearch").FirstOrDefault() as FullSearch;
                fs.IsVisible = false;
                fs.PageData  = null;
            }

            AdvancedSearchResults res = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearchResults").FirstOrDefault() as AdvancedSearchResults;

            if (res == null)
            {
                AdvancedSearchResults hp = new AdvancedSearchResults();
                hp.PageData = filters;
                nav.Push(hp);
            }
            else
            {
                if (filters == null ||
                    (filters != null && filters.AllFilters == null && filters.StructureSearch == null) ||
                    (filters != null && filters.AllFilters != null && filters.AllFilters.Count == 0 && filters.StructureSearch == null)
                    )
                {
                    string selectedSource = filters.SelectedSource;
                    filters = res.PageData as AdvSearchFiltersAll;
                    if (selectedSource != null)
                    {
                        filters.SelectedSource = selectedSource;
                    }
                }
                else
                {
                    res.PageData  = filters;
                    res.IsVisible = true;
                    nav.Push(res);
                }
            }

            nav.LastNavigable = "AdvancedSearchResults";

            if (filters != null && filters.AllFilters != null)
            {
                foreach (var item in filters.AllFilters)
                {
                    var pUnits            = materialContextUow.PropertyUnits.AllAsNoTracking.Where(n => n.PropertyID == item.propertyId).ToList();
                    PropertyUnitModel pum = new PropertyUnitModel()
                    {
                        PropertyType = item.propertyType,
                        UniqueID     = Guid.NewGuid().ToString("N"),
                        PropertyID   = item.propertyId,
                        PropertyName = item.propertyName,
                        IsPropertyConditionsActive = item.isPropertyConditionsActive,
                        Units = new List <UnitModel>()
                    };
                    foreach (var u in pUnits.Where(i => i.UnitKey != null))
                    {
                        pum.Units.Add(new UnitModel()
                        {
                            Factor = (double)u.Factor, Metric = (bool)u.Metric, Offset = (double)u.Offset, UnitKey = (int)u.UnitKey, UnitLabel = u.UnitLabel
                        });
                    }
                    pum.SelectedUnit    = item.unitId;
                    pum.SelectedBinary  = item.binaryOperators;
                    pum.SelectedLogical = item.logicalOperators;
                    pum.ValueFrom       = item.valueFrom_orig == null ? "" : item.valueFrom_orig.ToString();
                    pum.ValueTo         = item.valueTo_orig == null ? "" : item.valueTo_orig.ToString();

                    // Fill property conditions
                    pum.PropertyConditions = new List <PropertyConditionModel>();

                    foreach (var cond in item.PropertyConditions)
                    {
                        PropertyConditionModel oneCondition = new PropertyConditionModel()
                        {
                            Condition = new AdvSearchPropertyConditions()
                            {
                                PropertyID = cond.Condition.PropertyID,
                                X_label    = cond.Condition.X_label,
                                UnitGroup  = cond.Condition.UnitGroup
                            },
                            SelectedLogical = cond.SelectedLogical,
                            ValueFrom       = cond.ValueFrom,
                            ValueTo         = cond.ValueTo
                        };
                        oneCondition.FillUnits();

                        pum.PropertyConditions.Add(oneCondition);
                    }


                    units.Add(pum);
                }

                adv.PageData = units;
            }



            System.Web.HttpContext.Current.Session["Navigation"] = nav;
            return(filters);
        }
        public JsonResult ApplyPager(GridDescriptor request)
        {
            BreadcrumbNavigation nav = (BreadcrumbNavigation)System.Web.HttpContext.Current.Session["Navigation"];

            if (nav == null)
            {
                nav = new BreadcrumbNavigation();
            }
            AdvSearchFiltersAll filters = new AdvSearchFiltersAll();

            AdvancedSearchResults res = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearchResults").FirstOrDefault() as AdvancedSearchResults;

            if (res != null)
            {
                filters = res.PageData as AdvSearchFiltersAll;
            }
            nav.LastNavigable = "AdvancedSearchResults";
            System.Web.HttpContext.Current.Session["Navigation"] = nav;

            BaseSearchModel model = new BaseSearchModel();

            if (request.Pager == null)
            {
                request = new GridDescriptor(new SortDescriptor()
                {
                    PropertyName = "Name", Order = SortOrder.Ascending
                });
            }
            model.Descriptor = request;
            if (filters.StructureSearch != null)
            {
                StringBuilder sb = new StringBuilder(65536);

                byte[] bytesData = Encoding.ASCII.GetBytes("query=" + filters.StructureSearch.Query + ";exactsearch=" + filters.StructureSearch.Exactsearch + ";stereo=" + filters.StructureSearch.Stereo + "\0");

                var    result    = StructureSearch(bytesData, sb, sb.Capacity);
                string recordIds = sb.Replace(";", ",").ToString().Trim().TrimEnd(',');

                if (!string.IsNullOrEmpty(recordIds))
                {
                    model.ListOfMaterials = _searchResultsBinder.GetResultsStructureAdvSearch(recordIds, request, materialContextUow);
                }
                model.IsStructureSearch = true;
            }
            else
            {
                model.ListOfMaterials = _searchResultsBinder.GetResultsAdvSearch(filters, request, materialContextUow);
            }
            SearchResultsCondition filterModel = new SearchResultsCondition();

            //filterModel.ClasificationId = filters.ClasificationId;
            //filterModel.ClasificationTypeId = filters.ClasificationTypeId;
            filterModel.FullText = "";
            filterModel.ShowPropertiesFilters = false;
            filterModel.FromBrowse            = false;
            filterModel.FromAdvanced          = true;
            // add Sources to model
            filterModel.Sources        = materialContextUow.Sources.AllAsNoTracking.OrderBy(m => m.Id).ThenBy(n => n.Name).ToList();
            filterModel.SelectedSource = filters.SelectedSource;
            model.Filter = filterModel;
            //BreadcrumbNavigationGetSet(filters);

            return(Json(ResponseStatus.Success, RenderPartialViewToString("AdvResultsContainer", model), JsonRequestBehavior.AllowGet));
        }
        public ActionResult FullTextSearchOnly(SearchFilters filters)
        {
            BaseSearchModel model = new BaseSearchModel();

            model = _searchResultsBinder.GetResultsFullTextSearch(filters, new GridDescriptor(new SortDescriptor()
            {
                PropertyName = "Name", Order = SortOrder.Ascending
            }), materialContextUow);

            model.HasSearchFilters = HasSearchFiltersEnum.Yes;


            BreadcrumbNavigation nav = (BreadcrumbNavigation)System.Web.HttpContext.Current.Session["Navigation"];

            if (nav == null)
            {
                nav = new BreadcrumbNavigation();
            }
            if (nav.Contains("AdvancedSearch"))
            {
                AdvancedSearchNav asn = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearch").FirstOrDefault() as AdvancedSearchNav;
                asn.PageData  = null;
                asn.IsVisible = false;
            }
            if (nav.Contains("AdvancedSearchResults"))
            {
                AdvancedSearchResults asn = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearchResults").FirstOrDefault() as AdvancedSearchResults;
                asn.PageData  = null;
                asn.IsVisible = false;
            }
            if (nav.Contains("Exporter"))
            {
                nav.Pop();
            }
            if (nav.Contains("Comparison"))
            {
                nav.Pop();
            }
            if (nav.Contains("MaterialDetails1"))
            {
                nav.Pop();
            }
            if (nav.Contains("Subgroups"))
            {
                nav.Pop();
            }
            if (nav.Contains("BrowseFacets"))
            {
                nav.Pop();
            }
            if (nav.Contains("BrowseHome"))
            {
                nav.Pop();
            }
            System.Web.HttpContext.Current.Session["AdvancedSearchFilter"] = null;

            Session["ClassificationSelection"] = null;
            Session["ClassificationIds"]       = "";
            IDictionary <string, object> allFilters = new Dictionary <string, object>();

            allFilters.Add("filters", filters);
            allFilters.Add("advFilters", null);
            FullSearch fs = nav.GetOrderedItems().Where(n => n.NavigableID == "FullSearch").FirstOrDefault() as FullSearch;

            if (fs == null)
            {
                fs = new FullSearch();
            }
            fs.IsVisible      = true;
            fs.PageData       = allFilters;
            nav.LastNavigable = "FullSearch";
            nav.Push(fs);
            new TableFiltersBinder().resetAllTableFilters();
            return(View("Search", model));
        }
        public IDictionary <string, object> BreadcrumbNavigationGetSet(SearchFilters filters, AdvSearchFiltersAll advFilters, bool browse = false, string classIds = "")
        {
            BreadcrumbNavigation nav = (BreadcrumbNavigation)System.Web.HttpContext.Current.Session["Navigation"];

            if (nav == null)
            {
                nav = new BreadcrumbNavigation();
            }
            if (nav.Contains("Exporter"))
            {
                nav.Pop();
            }
            if (nav.Contains("Comparison"))
            {
                nav.Pop();
            }
            if (nav.Contains("MaterialDetails1"))
            {
                nav.Pop();
            }
            if (nav.Contains("Subgroups"))
            {
                nav.Pop();
            }
            IDictionary <string, object> allFilters = new Dictionary <string, object>();

            foreach (var item in nav.GetOrderedItems().Where(n => n.NavigableID != "HomePage"))
            {
                item.IsVisible = false;
            }
            if (browse)
            {
                allFilters.Add("filters", filters);

                nav.GetOrderedItems().Where(n => n.NavigableID == "BrowseHome").FirstOrDefault().IsVisible = true;

                BrowseFacets bf = nav.GetOrderedItems().Where(n => n.NavigableID == "BrowseFacets").FirstOrDefault() as BrowseFacets;
                if (bf == null)
                {
                    bf = new BrowseFacets();

                    bf.PageData = allFilters;
                }
                else
                {
                    if (filters.ClasificationId == 0)
                    {
                        allFilters = (Dictionary <string, object>)bf.PageData;
                    }
                    else
                    {
                        bf.PageData = allFilters;
                    }
                }
                bf.IsVisible      = true;
                nav.LastNavigable = "BrowseFacets";
                nav.Push(bf);
            }
            else
            {
                allFilters.Add("filters", filters);
                allFilters.Add("advFilters", advFilters);


                if (nav.Contains("AdvancedSearch"))
                {
                    AdvancedSearchNav asn = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearch").FirstOrDefault() as AdvancedSearchNav;
                    asn.PageData  = null;
                    asn.IsVisible = false;
                }
                if (nav.Contains("AdvancedSearchResults"))
                {
                    AdvancedSearchResults asn = nav.GetOrderedItems().Where(n => n.NavigableID == "AdvancedSearchResults").FirstOrDefault() as AdvancedSearchResults;
                    asn.PageData  = null;
                    asn.IsVisible = false;
                }
                FullSearch fs = nav.GetOrderedItems().Where(n => n.NavigableID == "FullSearch").FirstOrDefault() as FullSearch;
                if (fs == null)
                {
                    HomePage hp = new HomePage();
                    hp.PageData         = 0;
                    ViewBag.TabSelected = hp.PageData;
                    nav.LastNavigable   = "HomePage";
                    hp.IsVisible        = true;
                    nav.Push(hp);

                    fs          = new FullSearch();
                    fs.PageData = allFilters;
                }
                else
                {
                    if (filters.filter == null && (filters.Source == null || filters.Source == "0") && (advFilters == null || advFilters.AllFilters == null))
                    {
                        allFilters = (Dictionary <string, object>)fs.PageData;
                    }
                    else
                    {
                        fs.PageData = allFilters;
                    }
                    if (!string.IsNullOrWhiteSpace(classIds))
                    {
                        Session["ClassificationIds"] = classIds;
                    }
                }

                fs.IsVisible      = true;
                nav.LastNavigable = "FullSearch";
                nav.Push(fs);
            }

            System.Web.HttpContext.Current.Session["Navigation"] = nav;
            return(allFilters);
        }