示例#1
0
        public async Task <IActionResult> Details([Bind("BlogID,CommentAuthorID,CommentPost,PublishDate")] BlogCommentViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Comment comment = new Comment();
                comment.CommentAuthorID = viewModel.CommentAuthorID;
                comment.CommentPost     = viewModel.CommentPost;
                comment.PublishDate     = viewModel.PublishDate;


                Blog blog = await _context.Blog
                            .SingleOrDefaultAsync(m => m.ID == viewModel.BlogID);

                if (blog == null)
                {
                    return(NotFound());
                }

                comment.BlogComment = blog;
                _context.Comment.Add(comment);
                await _context.SaveChangesAsync();

                viewModel = await GetBlogCommentViewModelFromBlog(blog);
            }
            return(View(viewModel));
        }
示例#2
0
        public ActionResult AddComment(BlogCommentViewModel blogcomment)
        {
            if (ModelState.IsValid)
            {
                var comments = new List <Comment>();

                var comment = new Comment
                {
                    Body = blogcomment.Body
                };

                comments.Add(comment);

                var post = new Post
                {
                    Id       = blogcomment.PostId,
                    Comments = comments
                };

                _repository.Update(post);
                return(View("Index", post));
            }

            return(View("Index"));
        }
示例#3
0
        public async Task <IActionResult> Comment(BlogCommentViewModel rate)
        {
            rate.BlogId = HttpContext.Session.Get <int>(CommonConstants.BlogId);
            await _blogCommentService.Add(rate);

            return(new OkObjectResult(rate));
        }
        public async Task <BaseReponse <ModelListResult <BlogCommentViewModel> > > GetAllPaging(BlogCommentRequest request)
        {
            var query = await _blogCommentRepository.FindAll();

            if (request.BlogId > 0)
            {
                query = query.Where(x => x.BlogId == request.BlogId);
            }

            int totalRow = query.Count();

            query = query.OrderByDescending(x => x.DateCreated)
                    .Skip(request.PageIndex * request.PageSize)
                    .Take(request.PageSize);

            var items = new BlogCommentViewModel().Map(query).ToList();

            return(new BaseReponse <ModelListResult <BlogCommentViewModel> >
            {
                Data = new ModelListResult <BlogCommentViewModel>()
                {
                    Items = items,
                    Message = Message.Success,
                    RowCount = totalRow,
                    PageSize = request.PageSize,
                    PageIndex = request.PageIndex
                },
                Message = Message.Success,
                Status = (int)QueryStatus.Success
            });
        }
        public async Task <BlogCommentViewModel> Add(BlogCommentViewModel blogCommentVm)
        {
            var page = new BlogCommentViewModel().Map(blogCommentVm);
            await _blogCommentRepository.Add(page);

            _unitOfWork.Commit();
            return(blogCommentVm);
        }
        public IActionResult BlogComment(int id = 1)
        {
            BlogPost             post            = _db.blogposts.FirstOrDefault(b => b.Id == id);
            BlogCommentViewModel blogCommentView = new BlogCommentViewModel {
                BlogPost    = post,
                BlogComment = new BlogComment()
            };

            return(View(blogCommentView));
        }
示例#7
0
        private async Task <BlogCommentViewModel> GetBlogCommentViewModelFromBlog(Blog blog)
        {
            BlogCommentViewModel viewModel = new BlogCommentViewModel();

            viewModel.Blog = blog;
            List <Comment> comments = await _context.Comment
                                      .Where(m => m.BlogComment == blog).ToListAsync();

            viewModel.Comments = comments;
            return(viewModel);
        }
 public IActionResult Create(BlogCommentViewModel cmt)
 {
     if (ModelState.IsValid)
     {
         BlogComment model = _mapper.Map <BlogCommentViewModel, BlogComment>(cmt);
         model.CreatedBy = _admin.FullName;
         model.Image     = "#";
         _blogCommentsRepository.CreateComment(model);
         return(RedirectToAction("index"));
     }
     return(View(cmt));
 }
示例#9
0
        public JsonResult CommentSubmit(BlogCommentViewModel commentViewModel)
        {
            BlogPost blogPost = new BlogPost(commentViewModel.PostID);

            TKS.Models.User user = new TKS.Models.User();
            commentViewModel.Author      = user.UserName;
            commentViewModel.CommentDate = DateTime.Now;
            commentViewModel.Email       = user.Email;
            commentViewModel.IP          = Request.UserHostAddress;
            blogPost.AddComment(commentViewModel);

            return(Json(true));
        }
 /// <summary>
 /// 页面加载
 /// </summary>
 /// <param name="e"></param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (e.NavigationMode == NavigationMode.New)
     {
         Blog blog = (Blog)e.Parameter;
         BlogCommentViewModel = new BlogCommentViewModel(blog);
         BlogCommentViewModel.OnLoadMoreStarted += count => LoadingProgressRing.IsActive = true;
         BlogCommentViewModel.OnLoadMoreCompleted += count => LoadingProgressRing.IsActive = false;
         //BlogCommentViewModel.Refresh();
         //App.NavigationService.DetailFrame.Navigating += (sender, args) => LoadingProgressRing.IsActive = true;
         //App.NavigationService.DetailFrame.Navigated += (sender, args) => LoadingProgressRing.IsActive = false;
     }
     base.OnNavigatedTo(e);
 }
示例#11
0
 /// <summary>
 /// 页面加载
 /// </summary>
 /// <param name="e"></param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (e.NavigationMode == NavigationMode.New)
     {
         Blog blog = (Blog)e.Parameter;
         BlogCommentViewModel = new BlogCommentViewModel(blog);
         BlogCommentViewModel.OnLoadMoreStarted   += count => LoadingProgressRing.IsActive = true;
         BlogCommentViewModel.OnLoadMoreCompleted += count => LoadingProgressRing.IsActive = false;
         //BlogCommentViewModel.Refresh();
         //App.NavigationService.DetailFrame.Navigating += (sender, args) => LoadingProgressRing.IsActive = true;
         //App.NavigationService.DetailFrame.Navigated += (sender, args) => LoadingProgressRing.IsActive = false;
     }
     base.OnNavigatedTo(e);
 }
 public IActionResult Edit(BlogCommentViewModel cmt)
 {
     if (ModelState.IsValid)
     {
         BlogComment model = _mapper.Map <BlogCommentViewModel, BlogComment>(cmt);
         model.ModifiedBy = _admin.FullName;
         BlogComment BlogImageToUpdate = _blogCommentsRepository.GetCommentById(cmt.Id);
         if (BlogImageToUpdate == null)
         {
             return(NotFound());
         }
         _blogCommentsRepository.UpdateComment(BlogImageToUpdate, model);
         return(RedirectToAction("index"));
     }
     return(View(cmt));
 }
        public IEnumerable <BlogCommentViewModel> GetComments(int pageId, Guid formId)
        {
            var approvedRecords = GetApprovedRecords(pageId, formId);
            var viewModels      = new List <BlogCommentViewModel>();

            foreach (var record in approvedRecords)
            {
                var viewModel = new BlogCommentViewModel()
                {
                    Id      = string.Format("comment-{0}", record.UniqueId),
                    Created = record.Created,
                    Name    = record.GetValue <string>("name"),
                    Comment = record.GetValue <string>("comment")
                };

                viewModels.Add(viewModel);
            }

            return(viewModels.OrderBy(x => x.Created));
        }
示例#14
0
        internal static BlogCommentViewModel Make(BlogComment blogComment)
        {
            var vm = new BlogCommentViewModel
            {
                Name          = blogComment.CreatedBy != null ? blogComment.CreatedBy.Name : blogComment.Name,
                Modified      = blogComment.Modified,
                Created       = blogComment.Created,
                Body          = blogComment.Body,
                UserId        = blogComment.CreatedBy?.UserId,
                BlogCommentId = blogComment.BlogCommentId,
                Email         = blogComment.Email,
            };

            if (blogComment.CreatedBy != null)
            {
                vm.Name  = blogComment.CreatedBy.Name;
                vm.Email = blogComment.CreatedBy.Email;
            }
            return(vm);
        }
示例#15
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Blog blog = await _context.Blog
                        .FirstOrDefaultAsync(m => m.ID == id);

            if (blog == null)
            {
                return(NotFound());
            }
            BlogCommentViewModel viewModel = await GetBlogCommentViewModelFromBlog(blog);

            //var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); will give the user's userId
            var userName = User.FindFirstValue(ClaimTypes.Name);

            ViewData["userid"] = userName;
            return(View(viewModel));
        }
示例#16
0
 public IActionResult BlogComment(BlogCommentViewModel blogCommentView)
 {
     _db.blogcomments.Add(blogCommentView.BlogComment);
     _db.SaveChanges();
     return(RedirectToAction("Details", new { Id = blogCommentView.BlogComment.BlogPostId }));
 }