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 })); }
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 })); }