Exemplo n.º 1
0
        public async Task <ActionResult> Post(PostViewModel model)
        {
            var post  = _postRepository.GetByID(model.ID);
            var posts = _postRepository.GetAll();
            var user  = await _userRepository.GetUserByIdAsync(post.AuthorID);

            var categories  = _categoryRepository.GetAll();
            var tags        = new NEWSTags().GetPosTags(post.ID);
            var galleryNEWS = _postRepository.GetPostsHasGallery();
            var relatedPost = _postRepository.GetRelatedPost(post.ID, (long)post.CategoryID);
            var newsList    = (from item in posts
                               where item.CategoryID != null
                               select new NEWSPost
            {
                PostID = item.ID,
                Title = item.Title,
                ShortDescription = item.ShortDescription,
                ImageUrl = item.MainImageUrl,
                CreatePost = item.CreateDate,
                IsGallery = item.IsGallery,
                CommentCount = _commentRepository.GetCommentsByPost((long)post.ID).Count(),
                CategoryID = item.CategoryID,
                CategoryName = _categoryRepository.GetByID((long)item.CategoryID).Name
            }).ToList();



            var oldModel = new PostViewModel
            {
                ID               = post.ID,
                Title            = post.Title,
                Image            = post.MainImageUrl,
                ShortDescription = post.ShortDescription,
                LongDescription  = post.LongDescription,
                CreateDate       = (DateTime)post.CreateDate,
                IsGallery        = post.IsGallery,
                AuthorID         = post.AuthorID,
                AuthorName       = user.FirstName + ' ' + user.LastName,
                AuthorImage      = user.ImageUrl,
                CategoryID       = (long)post.CategoryID,
                CategoryName     = _categoryRepository.GetByID((long)post.CategoryID).Name,
                CategoryNEWS     = categories,
                Tags             = tags,
                CommentCount     = _commentRepository.GetCommentsByPost((long)post.ID).Count(),
                Comments         = _commentRepository.GetCommentsByPost((long)post.ID),
                GalleryNEWS      = (from item in galleryNEWS
                                    where item.CategoryID != null
                                    select new NEWSPost
                {
                    PostID = item.ID,
                    Title = item.Title,
                    ShortDescription = item.ShortDescription,
                    ImageUrl = item.MainImageUrl,
                    CreatePost = item.CreateDate,
                    IsGallery = item.IsGallery,
                    CategoryID = item.CategoryID,
                    CategoryName = _categoryRepository.GetByID((long)item.CategoryID).Name
                })
                                   .Skip(0)
                                   .Take(5)
                                   .ToList(),
                RelatedPost = (from item in relatedPost
                               where item.CategoryID != null
                               select new NEWSPost
                {
                    PostID = item.ID,
                    Title = item.Title,
                    ShortDescription = item.ShortDescription,
                    ImageUrl = item.MainImageUrl,
                    CreatePost = item.CreateDate,
                    IsGallery = item.IsGallery,
                    CategoryID = item.CategoryID,
                    CategoryName = _categoryRepository.GetByID((long)item.CategoryID).Name
                })
                              .Skip(0)
                              .Take(5)
                              .ToList(),
                TrendNEWS = newsList
                            .Skip(0)
                            .Take(5)
                            .ToArray(),
                LastNEWS = newsList
                           .OrderByDescending(p => p.CreatePost)
                           .Skip(5)
                           .Take(5)
                           .ToArray(),
            };

            if (post.PostGalleryID.HasValue)
            {
                model.GalleryRelatedPost = _galleryRepository.GetGallerysByPostGallery((long)post.PostGalleryID);
            }

            try
            {
                //oldModel.CommentID = model.CommentID;
                //oldModel.CommentName = model.CommentName;
                //oldModel.CommentEmail = model.CommentEmail;
                //oldModel.CommentWebsite = model.CommentWebsite;
                //oldModel.CommentReplyID = model.CommentReplyID;


                var comment = new Comment
                {
                    ID         = (model.CommentID != 0 ? model.CommentID : 0),
                    PersonName = model.CommentName,
                    Email      = model.CommentEmail,
                    Website    = model.CommentWebsite,
                    PostID     = (long)model.ID,
                    ReplyID    = (model.CommentReplyID != 0 ? model.CommentReplyID : 0),
                    Desciption = model.CommentContent,
                    CreateDate = DateTime.Now
                };

                _commentRepository.Save(comment);



                return(View(model.IsGallery == true ? "PostWithOutGallery" : "Post", oldModel));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, e.Message);
                return(View(model.IsGallery == true ? "PostWithOutGallery" : "Post", oldModel));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Post(long?ID)
        {
            var post  = _postRepository.GetByID((long)ID);
            var posts = _postRepository.GetAll();
            var user  = await _userRepository.GetUserByIdAsync(post.AuthorID);

            var categories  = _categoryRepository.GetAll();
            var tags        = new NEWSTags().GetPosTags(post.ID);
            var galleryNEWS = _postRepository.GetPostsHasGallery();

            var relatedPost = _postRepository.GetRelatedPost(post.ID, (long)post.CategoryID);
            var newsList    = (from item in posts
                               where item.CategoryID != null
                               select new NEWSPost
            {
                PostID = item.ID,
                Title = item.Title,
                ShortDescription = item.ShortDescription,
                ImageUrl = item.MainImageUrl,
                CreatePost = item.CreateDate,
                IsGallery = item.IsGallery,
                CommentCount = _commentRepository.GetCommentsByPost((long)post.ID).Count(),
                CategoryID = item.CategoryID,
                CategoryName = _categoryRepository.GetByID((long)item.CategoryID).Name
            }).ToList();



            var model = new PostViewModel
            {
                ID               = post.ID,
                Title            = post.Title,
                Image            = post.MainImageUrl,
                ShortDescription = post.ShortDescription,
                LongDescription  = post.LongDescription,
                CreateDate       = (DateTime)post.CreateDate,
                IsGallery        = post.IsGallery,
                AuthorID         = post.AuthorID,
                AuthorName       = user.FirstName + ' ' + user.LastName,
                AuthorImage      = user.ImageUrl,
                CategoryID       = (long)post.CategoryID,
                CategoryName     = _categoryRepository.GetByID((long)post.CategoryID).Name,
                CategoryNEWS     = categories,
                Tags             = tags,
                CommentCount     = _commentRepository.GetCommentsByPost((long)post.ID).Count(),
                Comments         = _commentRepository.GetCommentsByPost((long)post.ID),
                GalleryNEWS      = (from item in galleryNEWS
                                    where item.CategoryID != null
                                    select new NEWSPost
                {
                    PostID = item.ID,
                    Title = item.Title,
                    ShortDescription = item.ShortDescription,
                    ImageUrl = item.MainImageUrl,
                    CreatePost = item.CreateDate,
                    IsGallery = item.IsGallery,
                    CommentCount = _commentRepository.GetCommentsByPost((long)post.ID).Count(),
                    CategoryID = item.CategoryID,
                    CategoryName = _categoryRepository.GetByID((long)item.CategoryID).Name
                })
                                   .Skip(0)
                                   .Take(5)
                                   .ToList(),
                RelatedPost = (from item in relatedPost
                               where item.CategoryID != null
                               select new NEWSPost
                {
                    PostID = item.ID,
                    Title = item.Title,
                    ShortDescription = item.ShortDescription,
                    ImageUrl = item.MainImageUrl,
                    CreatePost = item.CreateDate,
                    IsGallery = item.IsGallery,
                    CommentCount = _commentRepository.GetCommentsByPost((long)post.ID).Count(),
                    CategoryID = item.CategoryID,
                    CategoryName = _categoryRepository.GetByID((long)item.CategoryID).Name
                })
                              .Skip(0)
                              .Take(5)
                              .ToList(),
                TrendNEWS = newsList
                            .Skip(0)
                            .Take(5)
                            .ToArray(),
                LastNEWS = newsList
                           .OrderByDescending(p => p.CreatePost)
                           .Skip(5)
                           .Take(5)
                           .ToArray(),
            };

            if (post.PostGalleryID.HasValue)
            {
                model.GalleryRelatedPost = _galleryRepository.GetGallerysByPostGallery((long)post.PostGalleryID);
            }

            return(View(model.IsGallery == true ? "PostWithOutGallery" : "Post", model));
        }