Esempio n. 1
0
        public SearchViewModel GetAllPressReleases( string language, int page, int page_size)
        {
            List<string> langs = new List<string>();
            if(website_languages.ContainsKey(language))
                langs = website_languages[language];

            SearchViewModel result = new SearchViewModel();

            IQueryable<KeyIssue> res = DbContext.KeyIssues.Where(k => k.IsOnline && langs.Contains(k.Language) && k.IsInNews && k.FileURL != null && k.FileURL != "" && k.Author.FullName == "LOGI");

            res = res.OrderByDescending(a => a.PublishDate);
           result.TotalCount = res.Count();

            if (result.TotalCount > (page * page_size))
            {
                result.ShowNext = true;
            }
            if (result.TotalCount > page_size && page > 1)
            {
                result.ShowPrev = true;
            }

            result.DisplayFrom = ((page - 1) * page_size) + 1;
            result.DisplayTo = (page) * page_size;
            if (result.TotalCount < result.DisplayTo)
                result.DisplayTo = result.TotalCount;

            result.KeyIssues = res.Include(a => a.Author).Include(a => a.Source).Skip((page - 1) * page_size).Take(page_size).Select(a => new SearchItemViewModel()
                {
                    Author = a.Author.FullName,
                    AuthorId = a.AuthorID,
                    FriendlyURL = a.FriendlyURL,
                    ID = a.ID,
                    ImageURL = (a.FeatureImageURL == null || a.FeatureImageURL == "")?a.Source.ImageURL:a.FeatureImageURL,
                    PublishDate = a.PublishDate,
                    Title = a.Title,
                    Source = a.Source.Name,
                    SourceID = a.SourceID
                }).ToList();

            int img_width = LogiConfig.KeyIssuesImageSizes.Where(a => a.Name == "SearchThumb").FirstOrDefault().Width;
            int img_height = LogiConfig.KeyIssuesImageSizes.Where(a => a.Name == "SearchThumb").FirstOrDefault().Height;

            foreach (SearchItemViewModel s in result.KeyIssues)
            {
                s.ImageURL = ImageService.GenerateImageFullPath(s.ImageURL, img_width.ToString(), img_height.ToString());
            }

            return result;

        }
Esempio n. 2
0
        public ActionResult AdvancedSearch(string keyword = null, int? topicId = null, int? authorId = null, int? sourceId = null, int? typeId = null, int? countryId = null, string language = null, DateTime? fromDate = null, DateTime? toDate = null, bool isVideo = true, bool isText = true, bool isPDF = true)
        {
            SearchViewModel view_model = new SearchViewModel();
            view_model.keyword = keyword;
            view_model.topicId = topicId;
            view_model.authorId = authorId;
            view_model.sourceId = sourceId;
            view_model.typeId = typeId;
            view_model.countryId = countryId;
            view_model.language = language;
            view_model.toDate = toDate;
            view_model.fromDate = fromDate;
            view_model.isVideo = isVideo;
            view_model.isText = isText;
            view_model.isPDF = isPDF;

            var lan = "en";
            bool isarabic = CultureHelper.GetCurrentCulture().Contains("ar");
            if (isarabic)
                lan = "ar";

            FillSources(sourceId, lan);
            FillTopics(topicId, lan);

            FillCountries(countryId, lan);
            FillAuthors(authorId, lan);
            FillTypes(typeId, lan);

            return View(view_model);
        }
Esempio n. 3
0
        public SearchViewModel GetSearchResult(
            string search_key,                             
            int? topicId, 
            int page, 
            int page_size, 
            int? authorId, 
            int? sourceId, 
            string orderby,
            int? typeId,
            int? countryId,
            string language,
            DateTime? fromDate,
            DateTime? toDate,
            bool isText,
            bool isPDF,
            bool isVideo,
            bool isInNews = false
            )
        {
            SearchViewModel result = new SearchViewModel();

            IQueryable<KeyIssue> res = DbContext.KeyIssues.Where(a => a.IsOnline);

            if (isInNews)
                res = res.Where(k => k.IsInNews == true);

            List<string> keywords = new List<string>();
            //search key
            if (search_key != null && search_key != "")
            {
                keywords = search_key.Trim().Split(',').ToList();
                res = res.Where(a => keywords.Any(k=> a.Title.Contains(k)) || //title contains any keywords
                    keywords.Any(k=> a.Description.Contains(k)) || //description contains any keywords
                    a.Tags.Where(t => keywords.Any(k=> t.Name.Contains(k))).Count() > 0); //any tag contains any keyword
            }
            //topic
            if (topicId != null)
                res = res.Where(a => a.TopicID == topicId);

            List<string> langs = new List<string>();
           
            //language
            if (language != null && language != "")
            {
               if (website_languages.ContainsKey(language))
                    langs = website_languages[language];
               res = res.Where(a => langs.Contains(a.Language));
            }
                
            //author
            if (authorId != null)
                res = res.Where(a => a.AuthorID == authorId);
            //Source
            if (sourceId != null)
                res = res.Where(a => a.SourceID == sourceId);
            //Type
            if (typeId != null)
                res = res.Where(a => a.TypeID == typeId);
            //Country
            if (countryId != null)
                res = res.Where(a => a.Countries.Where(c=> c.ID == countryId).Count() > 0);
            //From Date
            if(fromDate !=null)
                res = res.Where(a => DbFunctions.CreateDateTime(a.PublishDate.Year, a.PublishDate.Month, a.PublishDate.Day, a.PublishDate.Hour, a.PublishDate.Minute, a.PublishDate.Second) >= fromDate.Value);
            //To Date
            if (toDate != null)
                res = res.Where(a => DbFunctions.CreateDateTime(a.PublishDate.Year, a.PublishDate.Month, a.PublishDate.Day, a.PublishDate.Hour, a.PublishDate.Minute, a.PublishDate.Second) <= toDate.Value);
            //Is Video
            res = res.Where(a => (isVideo && a.FeatureVideoLink != null && a.FeatureVideoLink != "")
                || (isPDF && a.FileURL != null && a.FileURL != "")
                || (isText && a.Description != null && a.Description != ""));
            
            //orderby
           
            if (orderby == "relevance")
            {
                res = res.OrderByDescending(a => keywords.Count(k=> a.Title.Contains(k))).
                    ThenByDescending(a=> a.Tags.Where(t => keywords.Any(k=> t.Name.Contains(k))).Count()).
                    ThenByDescending(a => keywords.Count(k => a.Description.Contains(k)));
            }
            else if (orderby == "popular")
            {
                res = res.OrderByDescending(a => a.Views);
            }
            else
            { res = res.OrderByDescending(a => a.PublishDate); }

            

            result.TotalCount = res.Count();

            if (result.TotalCount > (page * page_size))
            {
                result.ShowNext = true;
            }
            if (result.TotalCount > page_size && page > 1)
            {
                result.ShowPrev = true;
            }

            result.DisplayFrom = ((page - 1) * page_size) + 1;
            result.DisplayTo = (page) * page_size;
            if (result.TotalCount < result.DisplayTo)
                result.DisplayTo = result.TotalCount;

            result.KeyIssues = res.Include(a => a.Author).Include(a => a.Source).Skip((page - 1) * page_size).Take(page_size).Select(a => new SearchItemViewModel()
                {
                    Author = a.Author.FullName,
                    AuthorId = a.AuthorID,
                    FriendlyURL = a.FriendlyURL,
                    ID = a.ID,
                    ImageURL = (a.FeatureImageURL == null || a.FeatureImageURL == "")?a.Source.ImageURL:a.FeatureImageURL,
                    PublishDate = a.PublishDate,
                    Title = a.Title,
                    Source = a.Source.Name,
                    SourceID = a.SourceID
                }).ToList();

            int img_width = LogiConfig.KeyIssuesImageSizes.Where(a => a.Name == "SearchThumb").FirstOrDefault().Width;
            int img_height = LogiConfig.KeyIssuesImageSizes.Where(a => a.Name == "SearchThumb").FirstOrDefault().Height;

            foreach (SearchItemViewModel s in result.KeyIssues)
            {
                s.ImageURL = ImageService.GenerateImageFullPath(s.ImageURL, img_width.ToString(), img_height.ToString());
            }

            return result;
        }