예제 #1
0
        public virtual ActionResult Index(string term)
        {
            ViewBag.Term = term;

            IEnumerable <LuceneBookModel> model = LuceneBookSearch.Search(term,
                                                                          "Name", "Description", "Name", "Title", "Author", "Publisher", "ISBN", "Description").Take(100);

            const string highlightPattern = @"<b style='color:red;'>$1</b>";

            foreach (LuceneBookModel book in model)
            {
                book.Name = Regex.
                            Replace(book.Name ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase);
                book.Description = Regex.
                                   Replace(book.Description ?? " ", string.Format("({0})", term), highlightPattern,
                                           RegexOptions.IgnoreCase);
                book.Author = Regex.
                              Replace(book.Author ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase);
                book.Publisher = Regex.
                                 Replace(book.Publisher ?? " ", string.Format("({0})", term), highlightPattern,
                                         RegexOptions.IgnoreCase);
                book.ISBN = Regex.
                            Replace(book.ISBN ?? " ", string.Format("({0})", term), highlightPattern, RegexOptions.IgnoreCase);
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView(model));
            }
            return(View(model));
        }
예제 #2
0
        public virtual ActionResult Delete(int id)
        {
            _postService.RemovePostById(id);
            _uow.SaveChanges();

            #region Remove lucene search index

            LuceneBookSearch.ClearLuceneIndexRecord(id);

            #endregion

            return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert {
                Message = "پست مورد نظر با موفقیت حذف شد"
            }));
        }
예제 #3
0
        public virtual ActionResult AutoCompleteSearch(string term)
        {
            if (string.IsNullOrWhiteSpace(term))
            {
                return(Content(string.Empty));
            }

            IEnumerable <LuceneBookModel> items =
                LuceneBookSearch.Search(term, "Name", "Title", "Author", "Publisher", "ISBN", "Description").Take(10);


            var data =
                items.Select(x => new
            {
                label = x.Name,
                url   =
                    Url.Action(MVC.Post.ActionNames.Index, MVC.Post.Name,
                               new { id = x.PostId, title = UrlExtensions.ResolveTitleForUrl(x.Title) })
            });

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
        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 book by Lucene.NET

                //Index updated book lucene.NET
                LuceneBookSearch.ClearLuceneIndexRecord(postModel.PostId);
                Post currentPost = _postService.Find(postModel.PostId);
                LuceneBookSearch.AddUpdateLuceneIndex(new LuceneBookModel
                {
                    Author      = currentPost.Book.Author,
                    Description = HtmlUtility.RemoveHtmlTags(currentPost.Book.Description),
                    ISBN        = currentPost.Book.ISBN,
                    Name        = currentPost.Book.Name,
                    PostId      = currentPost.Id,
                    Publisher   = currentPost.Book.Publisher,
                    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
            }));
        }
예제 #5
0
        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,
                Status        = postModel.PostStatus.ToString().ToLower(),
                Title         = postModel.PostTitle
            };

            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;
            post.User          = _userService.GetUserByUserName(User.Identity.Name);
            post.Labels        = _labelService.GetLabelsById(postModel.LabelId);

            _postService.AddPost(post);
            _uow.SaveChanges();

            #region Indexing new book by Lucene.NET

            //Index the new book lucene.NET
            Post lastPost = _postService.Find(post.Id);
            LuceneBookSearch.AddUpdateLuceneIndex(new LuceneBookModel
            {
                Author      = lastPost.Book.Author,
                Description = HtmlUtility.RemoveHtmlTags(lastPost.Book.Description),
                ISBN        = lastPost.Book.ISBN,
                Name        = lastPost.Book.Name,
                PostId      = lastPost.Id,
                Publisher   = lastPost.Book.Publisher,
                Title       = lastPost.Title
            });

            #endregion

            return(PartialView(MVC.Admin.Shared.Views._Alert,
                               new Alert {
                Message = "پست جدید با موقیت در سیستم ثبت شد", Mode = AlertMode.Success
            }));
        }
예제 #6
0
        public virtual ActionResult SilmilarPosts(int id)
        {
            IEnumerable <MorePostsLikeThis> model = LuceneBookSearch.GetMoreLikeThisPostItems(id).Skip(1);

            return(PartialView(MVC.Post.Views._SimilarPosts, model));
        }