public virtual ActionResult Index(string term, int page = 0, int count = 5) { ViewBag.Term = term; var RoutingKey = "search"; var _page = _pageService.FindByExternalLink(RoutingKey); if (_page != null) { TempData["PageTitle"] = _page.Title ?? "نتیجه جستجو"; TempData["PageSubtitle"] = _page.SubTitle ?? "جستجو در کل صفحات و مطالب سایت"; TempData["FeatureImage"] = _page.FeatureImage ?? "/Content/images/material/breadcrumb.jpg"; } else { TempData["PageTitle"] = "نتیجه جستجو"; TempData["PageSubtitle"] = "جستجو در کل صفحات و مطالب سایت"; TempData["FeatureImage"] = "/Content/images/material/breadcrumb.jpg"; } IEnumerable <LucenePostModel> allPosts = LucenePostSearch.Search(term, "Title", "Body", "Labels", "Keywords", "Description"); ViewBag.CurrentPage = page; ViewBag.TotalRecords = allPosts.Count(); ViewBag.Count = count; var model = allPosts.Skip(page * count).Take(count); const string highlightPattern = @"<b style='color:red;'>$1</b>"; foreach (LucenePostModel Post in model) { Post.Title = Regex. Replace(Post.Title ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase); Post.Description = Regex. Replace(Post.Description ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase); Post.Body = Regex. Replace(Post.Body ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase); Post.Labels = Regex. Replace(Post.Labels ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase); Post.Keywords = Regex. Replace(Post.Keywords ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase); } if (Request.IsAjaxRequest()) { return(PartialView(model)); } return(View(model)); }
public virtual ActionResult Delete(int id) { _postService.RemovePostById(id); _uow.SaveChanges(); #region Remove lucene search index new LucenePostSearch(_postService); LucenePostSearch.ClearLuceneIndexRecord(id); #endregion return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "دانشنامه مورد نظر با موفقیت حذف شد" })); }
public virtual ActionResult AutoCompleteSearch(string term) { if (string.IsNullOrWhiteSpace(term)) { return(Content(string.Empty)); } IEnumerable <LucenePostModel> items = LucenePostSearch.Search(term, "Title", "Body", "Labels", "Keywords", "Description").Take(10); var data = items.Select(x => new { label = x.Title, url = Url.Action(MVC.Post.ActionNames.Index, MVC.Post.Name, new { id = x.PostId, title = UrlExtensions.ResolveTitleForUrl(x.Title) }) }); return(Json(data, JsonRequestBehavior.AllowGet)); }
public virtual ActionResult EditPost(EditPostModel postModel) { if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } postModel.ModifiedDate = DateAndTime.GetDateTime(); postModel.EditedByUser = _userService.GetUserByUserName(User.Identity.Name); postModel.Labels = _labelService.GetLabelsById(postModel.LabelsId); // _downloadLinkService.RemoveByPostId(postModel.PostId); _uow.SaveChanges(); //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink1.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink1); //} //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink2.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink2); //} //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink3.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink3); //} //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink4.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink4); //} //postModel.Book.Description = postModel.Book.Description.ToSafeHtml(); postModel.PostBody = postModel.PostBody.ToSafeHtml(); UpdatePostStatus status = _postService.UpdatePost(postModel); if (status == UpdatePostStatus.Successfull) { _uow.SaveChanges(); #region Indexing updated Post by Lucene.NET new LucenePostSearch(_postService); //Index updated book lucene.NET LucenePostSearch.ClearLuceneIndexRecord(postModel.PostId); Post currentPost = _postService.Find(postModel.PostId); LucenePostSearch.AddUpdateLuceneIndex(new LucenePostModel { Labels = string.Join(" , ", currentPost.Labels.Select(l => l.Name).ToArray()), Body = HtmlUtility.RemoveHtmlTags(currentPost.Body), Description = currentPost.Description, Keywords = currentPost.Keyword, PostId = currentPost.Id, Title = currentPost.Title }); #endregion return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "اطلاعات با موفقیت به روز رسانی شد", Mode = AlertMode.Success })); } return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "خطا در به روز رسانی اطلاعات", Mode = AlertMode.Error })); }
public virtual ActionResult AddPost(AddPostModel postModel) { if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } postModel.PostBody = postModel.PostBody.ToSafeHtml(); //postModel.Book.Description = postModel.Book.Description.ToSafeHtml(); var post = new Post { Body = postModel.PostBody, CommentStatus = postModel.PostCommentStatus, CreatedDate = DateAndTime.GetDateTime(), Description = postModel.PostDescription, Keyword = postModel.PostKeyword, Picture = postModel.PostPicture, Status = postModel.PostStatus.ToString().ToLower(), Title = postModel.PostTitle, }; #region Comment //var book = new Book //{ // Author = postModel.Book.Author, // Description = postModel.Book.Description, // ISBN = postModel.Book.ISBN, // Language = postModel.Book.Language, // Name = postModel.Book.Name, // Year = postModel.Book.Year, // Publisher = postModel.Book.Publisher, // Page = postModel.Book.Page //}; //var bookImage = new BookImage //{ // Path = postModel.BookImage.Path, // Title = postModel.BookImage.Title, // Description = postModel.BookImage.Description, // UploadedDate = DateAndTime.GetDateTime() //}; //var links = new List<DownloadLink>(); //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink1.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink1); //} //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink2.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink2); //} //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink3.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink3); //} //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink4.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink4); //} //post.Book = book; //post.DownloadLinks = links; //post.Book.Image = bookImage; #endregion post.User = _userService.GetUserByUserName(User.Identity.Name); post.Labels = _labelService.GetLabelsById(postModel.LabelId); _postService.AddPost(post); _uow.SaveChanges(); #region Indexing new Post by Lucene.NET //Index the new Post lucene.NET new LucenePostSearch(_postService); Post lastPost = _postService.Find(post.Id); LucenePostSearch.AddUpdateLuceneIndex(new LucenePostModel { Labels = string.Join(" , ", lastPost.Labels.Select(l => l.Name).ToArray()), Body = HtmlUtility.RemoveHtmlTags(lastPost.Body), Description = lastPost.Description, Keywords = lastPost.Keyword, PostId = lastPost.Id, Title = lastPost.Title }); #endregion return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "دانشنامه جدید با موقیت در سیستم ثبت شد", Mode = AlertMode.Success })); }