예제 #1
0
        public UpdatePostStatus UpdatePost(EditPostModel postModel)
        {
            Post selectedPost = _posts.Find(postModel.PostId);

            int count = selectedPost.Labels.Count;
            for (int i = 0; i < count; i++)
            {
                selectedPost.Labels.Remove(selectedPost.Labels.ElementAt(i));
                count--;
            }

            selectedPost.Labels = postModel.Labels;

            selectedPost.DownloadLinks = postModel.DownloadLinks;

            selectedPost.Body = postModel.PostBody;
            selectedPost.Book.Author = postModel.Book.Author;
            selectedPost.Book.ISBN = postModel.Book.ISBN;
            selectedPost.Book.Language = postModel.Book.Language;
            selectedPost.Book.Name = postModel.Book.Name;
            selectedPost.Book.Page = postModel.Book.Page;
            selectedPost.Book.Year = postModel.Book.Year;
            selectedPost.Book.Description = postModel.Book.Description;
            selectedPost.Book.Publisher = postModel.Book.Publisher;

            selectedPost.Book.Image.Description = postModel.BookImage.Description;
            selectedPost.Book.Image.Path = postModel.BookImage.Path;
            selectedPost.Book.Image.Title = postModel.BookImage.Title;

            selectedPost.CommentStatus = postModel.PostCommentStatus;
            selectedPost.Description = postModel.PostDescription;
            selectedPost.Keyword = postModel.PostKeyword;
            selectedPost.ModifiedDate = postModel.ModifiedDate;
            selectedPost.Status = postModel.PostStatus;
            selectedPost.Title = postModel.PostTitle;

            return UpdatePostStatus.Successfull;
        }
예제 #2
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
            });
        }