public ActionResult AddMaterialToSearch(int materialId, string title, int nodetype)
        {
            string propertyName = "";

            if (nodetype == 1)
            {
                propertyName = "Type";
            }
            else if (nodetype == 2)
            {
                propertyName = "Class";
            }
            else if (nodetype == 3)
            {
                propertyName = "Subclass";
            }
            else if (nodetype == 4)
            {
                propertyName = "Group";
            }

            PropertyUnitModel pum = new PropertyUnitModel()
            {
                PropertyType = ElsevierMaterials.Models.Domain.AdvancedSearch.PropertyType.Material,
                UniqueID     = Guid.NewGuid().ToString("N"),
                PropertyID   = materialId,
                PropertyName = string.Concat(propertyName, ": ", title),
                Units        = new List <UnitModel>()
            };

            return(Json(ResponseStatus.Success, RenderPartialViewToString("AdvSearchConditionItem", pum), JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddToSearch(int propertyId)
        {
            var pUnits            = materialContextUow.PropertyUnits.AllAsNoTracking.Where(n => n.PropertyID == propertyId).ToList();
            PropertyUnitModel pum = new PropertyUnitModel()
            {
                PropertyType = ElsevierMaterials.Models.Domain.AdvancedSearch.PropertyType.Property, UniqueID = Guid.NewGuid().ToString("N"), PropertyID = pUnits[0].PropertyID, PropertyName = pUnits[0].PropertyName, Units = new List <UnitModel>()
            };

            foreach (var item in pUnits.Where(i => i.UnitKey != null).OrderByDescending(j => j.Metric).ThenBy(k => k.UnitLabel))
            {
                pum.Units.Add(new UnitModel()
                {
                    Factor = (double)item.Factor, Metric = (bool)item.Metric, Offset = (double)item.Offset, UnitKey = (int)item.UnitKey, UnitLabel = item.UnitLabel
                });
            }
            pum.SelectedUnit = pum.Units.Count > 0 ? (pum.Units[0] != null ? pum.Units[0].UnitKey : 0) : 0;

            return(Json(ResponseStatus.Success, RenderPartialViewToString("SearchConditionItem", pum), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetFilters(SearchFilters filters)
        {
            SearchResultsCondition       filterModel = GetFiltersModel(filters);
            IDictionary <string, object> allFilters  = BreadcrumbNavigationGetSet(filters, null);

            AdvSearchFiltersAll advFilters = new AdvSearchFiltersAll();

            if (allFilters.ContainsKey("advFilters"))
            {
                advFilters = (AdvSearchFiltersAll)allFilters["advFilters"];
            }
            IList <PropertyUnitModel> units = new List <PropertyUnitModel>();

            if (advFilters != null && advFilters.AllFilters != null)
            {
                foreach (var item in advFilters.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, 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();
                    units.Add(pum);
                }
            }

            return(Json(ResponseStatus.Success, new { showTitle = units.Count > 0 ? true : false, dataSearch = RenderPartialViewToString("FiltersContainerAdvProp", filterModel), dataAdv = RenderPartialViewToString("SearchConditionItemContainer", units) }, 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);
        }