Ejemplo n.º 1
0
        public static int SearchCount(int CategoryID, List <FilterQueryEntry> query)
        {
            var all = SearchQuery(query).Select(x => x.ID).Distinct().ToList();

            var children = CatalogBrowser.GetChildrenCategories(CategoryID) /*.JoinToString(";")*/;

/*
 *          children =
 *              children.Where(
 *                  x =>
 *                      CatalogBrowser.CategoriesList.Any(
 *                          z => z.Value.StoreProductsToCategories.Any(c => c.CategoryID == x))).ToList();
 */

            return(CatalogBrowser.CategoriesList.Where(x => children.Contains(x.Value.ID))
                   .Select(x => x.Value)
                   .SelectMany(x => x.StoreProductsToCategories)
                   .Select(x => x.ProductID)
                   .Intersect(all).Distinct().Count());

            /*
             *          var pids =
             *              CatalogBrowser.CategoriesList.SelectMany(x => x.Value.StoreProductsToCategories)
             *                  .Where(x => children.Contains(x.CategoryID));
             */
            /*var db = new DB();
             *
             *
             *
             * var products = db.getIntListByJoinedString(children.JoinToString(";"), ";")
             *  .Join(db.StoreProductsToCategories, x => x.ID, y => y.CategoryID,
             *      (x, y) => new { y.StoreProduct }).Where(x => !x.StoreProduct.Deleted).Select(x => x.StoreProduct);*/
        }
Ejemplo n.º 2
0
        public CategoryFilter(int CategoryID)
        {
            this.CategoryID = CategoryID;
            _db             = new DB();
            var cat = CatalogBrowser.GetCategory(CategoryID);

            if (cat != null)
            {
                BaseURL = cat.FullUrl;
            }
            FilterEntry  = _db.Filters.FirstOrDefault(x => x.CatID == CategoryID);
            FilterRootID = CategoryID;
            Filters      = new List <CategoryFilterItem>();

            if (FilterEntry == null)
            {
                FilterEntry = SearchFilterInRoot(CategoryID);
            }
            if (FilterEntry != null)
            {
                Filters =
                    FilterEntry.FilterItems.OrderBy(x => x.OrderNum)
                    .Select(x => new CategoryFilterItem(x, CategoryID))
                    .ToList()
                    .Where(x => !x.Item.CharID.HasValue || x.PossibleValues.Count > 1)
                    .ToList();
            }
        }
Ejemplo n.º 3
0
        public ActionResult AnimeView()
        {
            AnimeBlock block = null;

            if (CatalogBrowser.Init().IsCategoryPage)
            {
                block = db.AnimeBlocks.FirstOrDefault(x => x.CatID == CatalogBrowser.Init(Request.RawUrl).CurrentCategory.ID);
            }
            else
            {
                block = db.AnimeBlocks.FirstOrDefault(x => x.PageID == AccessHelper.CurrentPageInfo.ID);
            }
            return(PartialView(block));
        }
Ejemplo n.º 4
0
        public ActionResult Slider(int ViewID)
        {
            var browser = CatalogBrowser.Init();

            if (browser.IsProductPage)
            {
                return(PartialView());
            }
            if (browser.IsCategoryPage && /*!browser.CurrentCategory.ShowSlider*/ browser.CurrentCategory.ID != CatalogBrowser.Root.ID)
            {
                return(PartialView());
            }

            var db   = new DB();
            var info = AccessHelper.CurrentPageInfo;
            var data = db.CMSPageSliders.Where(
                x =>
                x.CMSPageID == info.CurrentPage.ID && x.LangID == info.CurrentLang.ID &&
                x.ViewID == ViewID).Where(x => x.Visible).OrderBy(x => x.OrderNum);

            return
                (PartialView(data.ToList()));
        }
Ejemplo n.º 5
0
        public CommonSearch(string css = "")
        {
            if (css.IsNullOrEmpty())
            {
                CSS = "search_field_text";
            }
            else
            {
                CSS = css;
            }
            var browser = CatalogBrowser.Init();

            NeedShowSection = (browser.IsCategoryPage || browser.IsProductPage || browser.IsMainPage) && browser.CurrentCategory.ID > 1;
            var decode = HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["word"]);

            if (decode != null)
            {
                SearchQuery = decode.Trim();
            }

            SectionID            = NeedShowSection ? browser.CurrentCategory.ID : 0;
            OnlyInCurrentSection = SectionID.HasValue;
        }
Ejemplo n.º 6
0
        public ActionResult Recicle(FormCollection collection)
        {
            if (!collection["Restore"].IsNullOrEmpty())
            {
                foreach (string key in collection.Keys)
                {
                    if (key.StartsWith("p"))
                    {
                        var p = db.StoreProducts.FirstOrDefault(x => x.ID == key.Substring(1).ToInt());
                        if (p != null)
                        {
                            p.Deleted = false;
                            db.SubmitChanges();
                            CatalogBrowser.Init().ClearAllCaches();
                        }
                    }
                    if (key.StartsWith("c"))
                    {
                        var c = db.StoreCategories.FirstOrDefault(x => x.ID == key.Substring(1).ToInt());
                        if (c != null)
                        {
                            RestoreCats(c);
                            db.SubmitChanges();
                            CatalogBrowser.Init().ClearAllCaches();
                        }
                    }
                    if (key.StartsWith("x"))
                    {
                        var page = db.CMSPages.FirstOrDefault(x => x.ID == key.Substring(1).ToInt());
                        if (page != null)
                        {
                            RestorePages(page);
                            db.SubmitChanges();
                            CMSPage.ClearAllCache();
                        }
                    }
                }
            }
            else if (!collection["Delete"].IsNullOrEmpty())
            {
                foreach (string key in collection.Keys)
                {
                    if (key.StartsWith("p"))
                    {
                        var p = db.StoreProducts.FirstOrDefault(x => x.ID == key.Substring(1).ToInt());
                        if (p != null)
                        {
                            DeleteProductData(p);
                            db.StoreProducts.DeleteOnSubmit(p);
                            db.SubmitChanges();
                            CatalogBrowser.Init().ClearAllCaches();
                        }
                    }
                    if (key.StartsWith("c"))
                    {
                        var c = db.StoreCategories.FirstOrDefault(x => x.ID == key.Substring(1).ToInt());
                        if (c != null)
                        {
                            DeleteCategory(c);
                            CatalogBrowser.Init().ClearAllCaches();
                        }
                    }
                    if (key.StartsWith("x"))
                    {
                        var page = db.CMSPages.FirstOrDefault(x => x.ID == key.Substring(1).ToInt());
                        if (page != null)
                        {
                            DeletePage(page);
                            CMSPage.ClearAllCache();
                        }
                    }
                }
            }
            else if (!collection["Clear"].IsNullOrEmpty())
            {
                var recicle = db.CMSPages.Where(x => x.Deleted).ToList().Select(x => x.LoadLangValues()).Select(x => new RecicleItem()
                {
                    Name = x.PageName, Code = "x" + x.ID
                }).ToList();
                recicle.AddRange(db.StoreCategories.Where(x => x.Deleted)
                                 .Select(x => new RecicleItem()
                {
                    Name = x.Name, Code = "c" + x.ID
                }));
                recicle.AddRange(db.StoreProducts.Where(x => x.Deleted).Select(x => new RecicleItem()
                {
                    Name = x.Name, Code = "p" + x.ID
                }));
                foreach (var item in recicle)
                {
                    if (item.Code.StartsWith("p"))
                    {
                        var p = db.StoreProducts.FirstOrDefault(x => x.ID == item.Code.Substring(1).ToInt());
                        if (p != null)
                        {
                            DeleteProductData(p);
                            db.StoreProducts.DeleteOnSubmit(p);
                            db.SubmitChanges();
                            CatalogBrowser.Init().ClearAllCaches();
                        }
                    }
                    if (item.Code.StartsWith("c"))
                    {
                        var c = db.StoreCategories.FirstOrDefault(x => x.ID == item.Code.Substring(1).ToInt());
                        if (c != null)
                        {
                            DeleteCategory(c);
                            CatalogBrowser.Init().ClearAllCaches();
                        }
                    }
                    if (item.Code.StartsWith("x"))
                    {
                        var page = db.CMSPages.FirstOrDefault(x => x.ID == item.Code.Substring(1).ToInt());
                        if (page != null)
                        {
                            DeletePage(page);
                            CMSPage.ClearAllCache();
                        }
                    }
                }
            }


            return(Recicle());
        }
Ejemplo n.º 7
0
        public static CommonPageInfo InitFromQueryParams(List <string> allSlashedParams, List <KeyValuePair <string, string> > queryParams)
        {
            var db  = new DB();
            var url = "";

            foreach (var allSlashedParam in allSlashedParams)
            {
            }


            var slashedParams =
                allSlashedParams.Where(x => AccessHelper.CurrentLang.AvailableList.All(z => z.ShortName != x)).ToList();

            //var request = HttpContext.Current.Request;
            url = slashedParams.All(x => x.IsNullOrEmpty())
                      ? db.CMSPages.First(x => x.PageType.TypeName == "Catalog").URL
                      : slashedParams.Last(x => !x.IsNullOrEmpty());



            var            routes = new RouteValueDictionary();
            CommonPageInfo info;
            var            main = CatalogBrowser.ParentPage;

            if (main == null)
            {
                main = db.CMSPages.FirstOrDefault(x => x.PageType.TypeName == "MainPage");
            }
            if (main == null)
            {
                main = db.CMSPages.First();
            }

            if (slashedParams.Any() && slashedParams[0] == "Master")
            {
                var offset = AccessHelper.CurrentLang.AvailableList.Any(z => slashedParams.Contains(z.ShortName)) ? 0 : 1;
                routes = ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData.Values;
                if (routes.ContainsKey("url"))
                {
                    return(InitFromQueryParams(routes["url"].ToString()));
                }

                if (slashedParams.Count == 1)
                {
                    slashedParams.Add(AccessHelper.MasterPanel.DefaultController);
                    slashedParams.Add(AccessHelper.MasterPanel.DefaultAction);
                }

                if (slashedParams.Count < 3)
                {
                    slashedParams.Add("Index");
                }



                info = new CommonPageInfo()
                {
                    Controller  = slashedParams[2 - offset],
                    Action      = slashedParams[3 - offset],
                    CurrentPage = main.LoadLangValues(),
                    CurrentLang = AccessHelper.CurrentLang,
                    Layout      = "_Master",
                    Routes      = ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData.Values
                };
                return(info);
            }

            var pathPairs =
                slashedParams.Where(x => !x.IsNullOrEmpty()).Select((x, index) => new { Key = "url" + (index + 1), Value = x }).ToList();



            var cntBefore = pathPairs.Count;

            pathPairs = pathPairs.Where(x => !CatalogBrowser.CategoriesList.ContainsKey(x.Value) || x.Value == "catalog").ToList();
            pathPairs = pathPairs.Where(x => !CatalogBrowser.Products.ContainsValue(x.Value) || x.Value == "catalog").ToList();
            if (pathPairs.Count != cntBefore && pathPairs.Count > 0)
            {
                url = pathPairs.Last().Value;
            }

            foreach (var pair in pathPairs)
            {
                routes.Add(pair.Key, pair.Value);
            }
            foreach (var pair in queryParams)
            {
                routes.Add(pair.Key, pair.Value);
            }
            var cmsPage = db.CMSPages.FirstOrDefault(x => x.URL.ToLower() == url.ToLower());
            var browser = CatalogBrowser.Init();

            if (cmsPage == null && CatalogBrowser.CategoriesList.ContainsKey(url.ToLower()))
            {
                cmsPage = db.CMSPages.FirstOrDefault(x => x.ID == main.ID);
            }

/*
 *          var trunks = url.Split<string>("-").ToList();
 *          if (trunks.Count() > 1 && CatalogBrowser.Products.ContainsKey(trunks.Last().ToInt()))
 *          {
 *              cmsPage = db.CMSPages.FirstOrDefault(x => x.ID == main.ID);
 *          }
 *          else
 *          {
 */

            if (cmsPage == null && CatalogBrowser.Products.ContainsValue(url.ToLower()))
            {
                cmsPage = db.CMSPages.FirstOrDefault(x => x.ID == main.ID);
            }

/*
 *          }
 */

            if (cmsPage == null || (slashedParams.Any() && slashedParams[0] == "404") || (CatalogBrowser.ParentPage != null && CatalogBrowser.ParentPage.ID == cmsPage.ID && browser.IsNotFound(cmsPage)))
            {
                info = new CommonPageInfo
                {
                    URL         = "404",
                    Action      = "NotFound",
                    Controller  = "TextPage",
                    CurrentPage = main.LoadLangValues(),
                    CurrentLang = AccessHelper.CurrentLang,
                    Routes      = ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData.Values,
                    StatusCode  = 404,
                    Title       = SiteSetting.Get <string>("CommonTitle") + "Страница не найдена"
                };
            }
            else
            {
                info = new CommonPageInfo()
                {
                    ID          = cmsPage.ID,
                    URL         = url,
                    CurrentPage = cmsPage.LoadLangValues(),
                    Routes      = routes,
                    CurrentLang = AccessHelper.CurrentLang,
                    StatusCode  = 200
                };
                info.CurrentPage.Title = SiteSetting.Get <string>("CommonTitle") +
                                         (cmsPage.Title.IsNullOrEmpty() ? cmsPage.PageName : cmsPage.Title);
                if (browser.IsCategory(cmsPage))
                {
                    if (browser.CurrentCategory.ID == 1)
                    {
                        info.CurrentPage.Title = SiteSetting.Get <string>("CommonTitle") +
                                                 cmsPage.Title;
                        info.CurrentPage.Keywords    = cmsPage.Keywords;
                        info.CurrentPage.Description = cmsPage.Description;
                    }
                    else
                    {
                        info.CurrentPage.Title = SiteSetting.Get <string>("CommonTitle") +
                                                 browser.CurrentCategory.PageTitle;
                        info.CurrentPage.Keywords    = browser.CurrentCategory.PageKeywords;
                        info.CurrentPage.Description = browser.CurrentCategory.PageDescription;
                    }
                }
                if (browser.IsProductPage)
                {
                    info.CurrentPage.Title       = SiteSetting.Get <string>("CommonTitle") + browser.CurrentProduct.PageTitle;
                    info.CurrentPage.Keywords    = browser.CurrentProduct.PageKeywords;
                    info.CurrentPage.Description = browser.CurrentProduct.PageDescription;
                }
            }

            info.Layout = "MainPage";
            if (cmsPage != null)
            {
                var currentRole = AccessHelper.CurrentRole;
                var rel         = db.CMSPageRoleRels.FirstOrDefault(
                    x =>
                    x.PageID == cmsPage.ID &&
                    (!HttpContext.Current.User.Identity.IsAuthenticated || currentRole.IsNullOrEmpty()
                         ? !x.RoleID.HasValue
                         : x.Role.RoleName == currentRole));

                if (rel == null)
                {
                    info.Controller = "TextPage";
                    info.Action     = "AccessDenied";
                    info.Layout     = "MainPage";
                    info.StatusCode = 403;
                    info.Title      = SiteSetting.Get <string>("CommonTitle") + "Доступ к этой странице ограничен";
                }


                info.Layout = cmsPage.PageType.CMSPageTemplate.Layout;
            }
            return(info);
        }
Ejemplo n.º 8
0
        public PartialViewResult changeOrder(int id, int?value, int page, string tablename, string uidname, string ordername, string cc, string ca, string addqs, string query)
        {
            if (!value.HasValue)
            {
                return(PartialView());
            }
            var    db     = new DB();
            var    table  = db.GetTableByName(tablename);
            object target = null;
            var    all    = new List <KeyValuePair <object, int> >();

            foreach (var item in table)
            {
                if ((int)item.GetPropertyValue(uidname) == id)
                {
                    target = item;
                }
                else
                {
                    all.Add(new KeyValuePair <object, int>(item, (int)item.GetPropertyValue(ordername)));
                }
            }
            if (target == null)
            {
                return(PartialView());
            }

            if (all.Any())
            {
                all = all.OrderBy(x => x.Value).ToList();
                int pos = value.Value - 1;
                if (pos <= 0)
                {
                    pos = 0;
                }
                int max = all.Max(x => x.Value);
                if (pos >= max)
                {
                    all.Add(new KeyValuePair <object, int>(target, max + 1));
                }
                else
                {
                    all.Insert(pos, new KeyValuePair <object, int>(target, pos));
                }
                int counter = 1;
                foreach (var rec in all)
                {
                    rec.Key.SetPropertyValue(ordername, counter);
                    counter++;
                }
            }
            else
            {
                target.SetPropertyValue(ordername, 1);
            }
            db.Refresh(RefreshMode.KeepChanges);
            db.SubmitChanges();


            var qp = (addqs ?? "").Split <string>("&").ToList();


            var model = GetModel(cc, ca, new object[] { "List", page, id }, qp.Any() ? qp.ToArray() : null, query);

            CatalogBrowser.Init().ClearAllCaches();
            return(PartialView("UniversalList", model));
        }
Ejemplo n.º 9
0
        public static SiteMapItem GetCatalogRoot(int?root)
        {
/*
 *          if (HttpContext.Current.Cache["CatalogRoot"] != null)
 *              return HttpContext.Current.Cache["CatalogRoot"] as SiteMapItem;
 */


            var db  = new DB();
            var dlo = new DataLoadOptions();

            dlo.LoadWith <StoreCategory>(x => x.StoreProductsToCategories);
            dlo.LoadWith <StoreProduct>(x => x.StoreProductsToCategories);
            //dlo.LoadWith<StoreCategory>(x=> x.StoreCategories);
            db.LoadOptions = dlo;

            var obj = db.StoreCategories.FirstOrDefault(x => x.ParentID == root);

            if (!root.HasValue)
            {
                obj = db.StoreCategories.FirstOrDefault(x => x.ParentID == null);
            }
            if (obj == null)
            {
                return(null);
            }
            var cr =
                obj.WrapWithEnumerable()
                .Select(
                    x =>
                    new SiteMapItem(
                        (id, dbx) => CatalogBrowser.CategoriesList[CatalogBrowser.Categories[id]],
                        (id, dbx) => CatalogBrowser.CategoriesList.Values.Where(v => v.ParentID == id).OrderBy(z => z.OrderNum).Select(c => (object)c).ToList(),
                        baseObject =>
            {
                var cat = (StoreCategory)baseObject;
                return(new SiteMapItem()
                {
                    BaseObject = cat,
                    ParentID = cat.ParentID,
                    ID = cat.ID,
                    Name = cat.Name,
                    Link = cat.FullUrl,
                    OrderNum = cat.OrderNum,
                    IsActive = CatalogBrowser.Init().ParentIds.Contains(cat.ID),
                    ShowInMenu = cat.ShowInMenu,
                    Description = cat.MenuUpperText,
                    Title = cat.Description.ClearHTML(),
                    Image = cat.MenuImageUrl

                            /*(cat.StoreProductsToCategories.OrderBy(c => c.OrderNum).LastOrDefault() ??
                             * new StoreProductsToCategory() { OrderNum = 99999 }).OrderNum*/
                });
            }, db)
            {
                Name        = x.Name,
                ID          = x.ID,
                ParentID    = x.ParentID,
                BaseObject  = x,
                IsActive    = CatalogBrowser.Init().ParentIds.Contains(x.ID),
                ShowInMenu  = x.ShowInMenu,
                Link        = x.FullUrl,
                OrderNum    = x.OrderNum,
                Description = x.MenuUpperText,
                Title       = x.Description.ClearHTML(),
                Image       = x.MenuImageUrl
            }).First();

/*
 *          HttpContext.Current.Cache.Add("CatalogRoot", cr, null, DateTime.Now.AddDays(1), Cache.NoSlidingExpiration,
 *              CacheItemPriority.High, null);
 */

            return(cr);
        }
Ejemplo n.º 10
0
 public CatalogMenu(string url = "")
 {
     CatalogMap     = SiteMapItem.GetCatalogRoot(null);
     CatalogBrowser = CatalogBrowser.Init(url);
 }