Esempio n. 1
0
        public ActionResult Index(string text)
        {
            var key = (string)text.Clone();

            List <int> groupIDs = new List <int>();

            var products = Products.AdvancedSearch(key);

            Products.FillProductItems(UserID, products, StaticValues.DefaultProductImageSize);

            var blogs     = Articles.SimpleSearch(key, ArticleStatus.Approved, StaticValues.DefaultPostImageSize);
            var producers = Producers.SimpleSearch(key, groupIDs, StaticValues.ProducerImageSize);
            var groups    = Groups.SimpleSearch(key);

            var isFa = Utilities.ContainsUnicodeCharacter(key);

            key = key.GetReversed(isFa);

            if (products.Count == 0)
            {
                products = Products.AdvancedSearch(key);
                Products.FillProductItems(UserID, products, StaticValues.DefaultProductImageSize);
            }

            if (blogs.Count == 0)
            {
                blogs = Articles.SimpleSearch(key, ArticleStatus.Approved, StaticValues.DefaultPostImageSize);
            }

            if (groups.Count == 0)
            {
                groups = Groups.SimpleSearch(key);
            }

            var mappedGroups = Mapper.Map <List <JsonProductGroup> >(groups);

            ViewBag.Title       = "جستجو - " + text;
            ViewBag.Description = "جستجوی کلمه '" + text + "'";
            ViewBag.Keywords    = "جستجو, " + text;
            ViewBag.OGImage     = StaticValues.WebsiteUrl + "/images/small-logo.jpg";

            var model = new AdvancedSearch
            {
                Products  = products,
                Blogs     = blogs,
                Producers = producers,
                Groups    = mappedGroups,
            };

            return(View(model: model));
        }