public IPagedList <ForumTopic> GetAllTopics(int forumId = 0, int customerId = 0, string keywords = "", ForumSearchType searchType = ForumSearchType.All, int limitDays = 0, int pageIndex = 0, int pageSize = int.MaxValue) { DateTime?limitDate = null; if (limitDays > 0) { limitDate = DateTime.Now.AddDays(-limitDays); } bool searchKeywords = !String.IsNullOrEmpty(keywords); bool searchTopicTitles = searchType == ForumSearchType.All || searchType == ForumSearchType.TopicTitlesOnly; bool searchPostText = searchType == ForumSearchType.All || searchType == ForumSearchType.PostTextOnly; var query1 = from ft in _forumTopicRepository.Table join fp in _forumPostRepository.Table on ft.Id equals fp.TopicId where (forumId == 0 || forumId == ft.Id) && (customerId == 0 || customerId == ft.CustomerId) && ( !searchKeywords || (searchTopicTitles && ft.Subject.Contains(keywords)) || (searchPostText && fp.Text.Contains(keywords))) && (!limitDate.HasValue || limitDate.Value <= ft.LastPostTime) select ft.Id; var query2 = from ft in _forumTopicRepository.Table where query1.Contains(ft.Id) orderby ft.TopicTypeId descending, ft.LastPostTime descending, ft.Id descending select ft; return(new PagedList <ForumTopic>(query2, pageIndex, pageSize)); }
public virtual async Task <IPagedList <ForumTopic> > GetAllTopics( int forumId = 0, string userId = null, string keywords = null, ForumSearchType searchType = ForumSearchType.All, int limitDays = 0, int pageIndex = 0, int pageSize = int.MaxValue) { DateTime?limitDate = null; if (limitDays > 0) { limitDate = DateTime.UtcNow.AddDays(-limitDays); } //we need to cast it to int, otherwise it won't work in SQLCE4 //we cannot use string.IsNullOrEmpty in query because it causes SqlCeException on SQLCE4 bool searchKeywords = !string.IsNullOrEmpty(keywords); bool searchTopicTitles = searchType == ForumSearchType.All || searchType == ForumSearchType.TopicTitlesOnly; bool searchPostText = searchType == ForumSearchType.All || searchType == ForumSearchType.PostTextOnly; using (var forumTopicConnection = forumTopicRepository.OpenConnection()) using (var forumPostConnection = forumPostRepository.UseConnection(forumTopicConnection)) { var query1 = from ft in forumTopicConnection.Query() join fp in forumPostConnection.Query() on ft.Id equals fp.TopicId where (forumId == 0 || ft.ForumId == forumId) && (userId == null || ft.UserId == userId) && ( !searchKeywords || (searchTopicTitles && ft.Subject.Contains(keywords)) || (searchPostText && fp.Text.Contains(keywords))) && (!limitDate.HasValue || limitDate.Value <= ft.LastPostTime) select ft.Id; var query2 = from ft in forumTopicConnection.Query() where query1.Contains(ft.Id) orderby ft.TopicType descending, ft.LastPostTime descending, ft.Id descending select ft; return(await Task.FromResult(new PagedList <ForumTopic>(query2, pageIndex, pageSize))); } }
public virtual async Task <SearchModel> PrepareSearch(string searchterms, bool?adv, string forumId, string within, string limitDays, int pageNumber = 1) { int pageSize = 10; var model = new SearchModel(); // Create the values for the "Limit results to previous" select list var limitList = new List <SelectListItem> { new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.AllResults"), Value = "0" }, new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.1day"), Value = "1" }, new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.7days"), Value = "7" }, new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.2weeks"), Value = "14" }, new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.1month"), Value = "30" }, new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.3months"), Value = "92" }, new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.6months"), Value = "183" }, new SelectListItem { Text = _localizationService.GetResource("Forum.Search.LimitResultsToPrevious.1year"), Value = "365" } }; model.LimitList = limitList; // Create the values for the "Search in forum" select list var forumsSelectList = new List <SelectListItem>(); forumsSelectList.Add( new SelectListItem { Text = _localizationService.GetResource("Forum.Search.SearchInForum.All"), Value = "", Selected = true, }); var separator = "--"; var forumGroups = await _forumService.GetAllForumGroups(); foreach (var fg in forumGroups) { // Add the forum group with value as '-' so it can't be used as a target forum id forumsSelectList.Add(new SelectListItem { Text = fg.Name, Value = "-" }); var forums = await _forumService.GetAllForumsByGroupId(fg.Id); foreach (var f in forums) { forumsSelectList.Add( new SelectListItem { Text = string.Format("{0}{1}", separator, f.Name), Value = f.Id.ToString() }); } } model.ForumList = forumsSelectList; // Create the values for "Search within" select list var withinList = new List <SelectListItem> { new SelectListItem { Value = ((int)ForumSearchType.All).ToString(), Text = _localizationService.GetResource("Forum.Search.SearchWithin.All") }, new SelectListItem { Value = ((int)ForumSearchType.TopicTitlesOnly).ToString(), Text = _localizationService.GetResource("Forum.Search.SearchWithin.TopicTitlesOnly") }, new SelectListItem { Value = ((int)ForumSearchType.PostTextOnly).ToString(), Text = _localizationService.GetResource("Forum.Search.SearchWithin.PostTextOnly") } }; model.WithinList = withinList; string forumIdSelected = forumId; model.ForumIdSelected = forumIdSelected; int withinSelected; int.TryParse(within, out withinSelected); model.WithinSelected = withinSelected; int limitDaysSelected; int.TryParse(limitDays, out limitDaysSelected); model.LimitDaysSelected = limitDaysSelected; int searchTermMinimumLength = _forumSettings.ForumSearchTermMinimumLength; model.ShowAdvancedSearch = adv.GetValueOrDefault(); model.SearchResultsVisible = false; model.NoResultsVisisble = false; model.PostsPageSize = _forumSettings.PostsPageSize; model.AllowPostVoting = _forumSettings.AllowPostVoting; try { if (!String.IsNullOrWhiteSpace(searchterms)) { searchterms = searchterms.Trim(); model.SearchTerms = searchterms; if (searchterms.Length < searchTermMinimumLength) { throw new GrandException(string.Format(_localizationService.GetResource("Forum.SearchTermMinimumLengthIsNCharacters"), searchTermMinimumLength)); } ForumSearchType searchWithin = 0; int limitResultsToPrevious = 0; if (adv.GetValueOrDefault()) { searchWithin = (ForumSearchType)withinSelected; limitResultsToPrevious = limitDaysSelected; } if (_forumSettings.SearchResultsPageSize > 0) { pageSize = _forumSettings.SearchResultsPageSize; } var topics = await _forumService.GetAllTopics(forumIdSelected, "", searchterms, searchWithin, limitResultsToPrevious, pageNumber - 1, pageSize); model.TopicPageSize = topics.PageSize; model.TopicTotalRecords = topics.TotalCount; model.TopicPageIndex = topics.PageIndex; foreach (var topic in topics) { var topicModel = await PrepareForumTopicRow(topic); model.ForumTopics.Add(topicModel); } model.SearchResultsVisible = (topics.Any()); model.NoResultsVisisble = !(model.SearchResultsVisible); return(model); } model.SearchResultsVisible = false; } catch (Exception ex) { model.Error = ex.Message; } //some exception raised model.TopicPageSize = pageSize; model.TopicTotalRecords = 0; model.TopicPageIndex = pageNumber - 1; return(model); }
/// <summary> /// Gets all forum topics /// </summary> /// <param name="forumId">The forum identifier</param> /// <param name="customerId">The customer identifier</param> /// <param name="keywords">Keywords</param> /// <param name="searchType">Search type</param> /// <param name="limitDays">Limit by the last number days; 0 to load all topics</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Forum Topics</returns> public virtual IPagedList<ForumTopic> GetAllTopics(int forumId = 0, int customerId = 0, string keywords = "", ForumSearchType searchType = ForumSearchType.All, int limitDays = 0, int pageIndex = 0, int pageSize = int.MaxValue) { DateTime? limitDate = null; if (limitDays > 0) { limitDate = DateTime.UtcNow.AddDays(-limitDays); } //we need to cast it to int, otherwise it won't work in SQLCE4 //we cannot use String.IsNullOrEmpty in query because it causes SqlCeException on SQLCE4 bool searchKeywords = !String.IsNullOrEmpty(keywords); bool searchTopicTitles = searchType == ForumSearchType.All || searchType == ForumSearchType.TopicTitlesOnly; bool searchPostText = searchType == ForumSearchType.All || searchType == ForumSearchType.PostTextOnly; var query1 = from ft in _forumTopicRepository.Table join fp in _forumPostRepository.Table on ft.Id equals fp.TopicId where (forumId == 0 || ft.ForumId == forumId) && (customerId == 0 || ft.CustomerId == customerId) && ( !searchKeywords || (searchTopicTitles && ft.Subject.Contains(keywords)) || (searchPostText && fp.Text.Contains(keywords))) && (!limitDate.HasValue || limitDate.Value <= ft.LastPostTime) select ft.Id; var query2 = from ft in _forumTopicRepository.Table where query1.Contains(ft.Id) orderby ft.TopicTypeId descending, ft.LastPostTime descending, ft.Id descending select ft; var topics = new PagedList<ForumTopic>(query2, pageIndex, pageSize); return topics; }
/// <summary> /// Gets all topics. /// </summary> /// <param name="forumId">The forum identifier.</param> /// <param name="customerId">The customer identifier.</param> /// <param name="keywords">The keywords.</param> /// <param name="searchType">Type of the search.</param> /// <param name="limitDays">The limit days.</param> /// <param name="pageIndex">Index of the page.</param> /// <param name="pageSize">Size of the page.</param> /// <returns>System.String.</returns> /// <remarks>Guidebee IT</remarks> public static string GetAllTopics(int forumId = 0, int customerId = 0, string keywords = "", ForumSearchType searchType = ForumSearchType.All, int limitDays = 0, int pageIndex = 0, int pageSize = int.MaxValue) { var forumService = EngineContext.Current.Resolve <IForumService>(); var forumTopicCore = forumService.GetAllTopics(forumId, customerId, keywords, searchType, limitDays, pageIndex, pageSize); var forumTopic = forumTopicCore.MapSourcePageList <ForumTopic, Domain.Forums.ForumTopic>(AutoMapperConfiguration.Mapper); return(JsonConvert.SerializeObject(forumTopic, Formatting.Indented, new PageListConverter <Domain.Forums.ForumTopic>())); }
/// <summary> /// Gets all forum topics /// </summary> /// <param name="forumId">The forum identifier</param> /// <param name="customerId">The customer identifier</param> /// <param name="keywords">Keywords</param> /// <param name="searchType">Search type</param> /// <param name="limitDays">Limit by the last number days; 0 to load all topics</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Forum Topics</returns> public virtual IPagedList<ForumTopic> GetAllTopics(int forumId, int customerId, string keywords, ForumSearchType searchType, int limitDays, int pageIndex, int pageSize) { DateTime? limitDate = null; if (limitDays > 0) { limitDate = DateTime.UtcNow.AddDays(-limitDays); } var query1 = from ft in _forumTopicRepository.Table join fp in _forumPostRepository.Table on ft.Id equals fp.TopicId where (forumId == 0 || ft.ForumId == forumId) && (customerId == 0 || ft.CustomerId == customerId) && ( // following line causes SqlCeException on SQLCE4 (comparing parameter to IS NULL in query) -works on SQL Server // String.IsNullOrEmpty(keywords) || ((searchType == ForumSearchType.All || searchType == ForumSearchType.TopicTitlesOnly) && ft.Subject.Contains(keywords)) || ((searchType == ForumSearchType.All || searchType == ForumSearchType.PostTextOnly) && fp.Text.Contains(keywords))) && (!limitDate.HasValue || limitDate.Value <= ft.LastPostTime) select ft.Id; var query2 = from ft in _forumTopicRepository.Table where query1.Contains(ft.Id) orderby ft.TopicTypeId descending, ft.LastPostTime descending, ft.Id descending select ft; var topics = new PagedList<ForumTopic>(query2, pageIndex, pageSize); return topics; }
/// <summary> /// Gets all forum topics /// </summary> /// <param name="forumId">The forum identifier</param> /// <param name="customerId">The customer identifier</param> /// <param name="keywords">Keywords</param> /// <param name="searchType">Search type</param> /// <param name="limitDays">Limit by the last number days; 0 to load all topics</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <returns>Forum Topics</returns> public IAPIPagedList <ForumTopic> GetAllTopics(int forumId = 0, int customerId = 0, string keywords = "", ForumSearchType searchType = ForumSearchType.All, int limitDays = 0, int pageIndex = 0, int pageSize = int.MaxValue) { return(_forumService.GetAllTopics(forumId, customerId, keywords, searchType, limitDays, pageIndex, pageSize).ConvertPagedListToAPIPagedList()); }
public virtual IPagedList <ForumTopic> GetAllTopics(int forumId, int customerId, string keywords, ForumSearchType searchType, int limitDays, int pageIndex, int pageSize) { DateTime?limitDate = null; if (limitDays > 0) { limitDate = DateTime.UtcNow.AddDays(-limitDays); } var query1 = from ft in _forumTopicRepository.Table join fp in _forumPostRepository.Table on ft.Id equals fp.TopicId where (forumId == 0 || ft.ForumId == forumId) && (customerId == 0 || ft.CustomerId == customerId) && (!limitDate.HasValue || limitDate.Value <= ft.LastPostTime) && ( ((searchType == ForumSearchType.All || searchType == ForumSearchType.TopicTitlesOnly) && ft.Subject.Contains(keywords)) || ((searchType == ForumSearchType.All || searchType == ForumSearchType.PostTextOnly) && fp.Text.Contains(keywords)) ) select ft.Id; var query2 = from ft in _forumTopicRepository.Table where query1.Contains(ft.Id) orderby ft.TopicTypeId descending, ft.LastPostTime descending, ft.Id descending select ft; var topics = new PagedList <ForumTopic>(query2, pageIndex, pageSize); return(topics); }