コード例 #1
0
 // GET:评论列表
 public IActionResult List(int?id)
 {
     if (id.HasValue)
     {
         // 获取云产品
         var product = _cloudProductService.FindById(id.Value);
         // 是否存在
         if (product != null)
         {
             var viewmodel = new CommentListViewModel
             {
                 ProductName  = product.ProductName,
                 Description  = product.ProductDesc,
                 Image        = product.Image,
                 ProductId    = product.Id,
                 PlatformId   = product.CloudPlatform.Id,
                 PlatformName = product.CloudPlatform.PlatformName
             };
             // 对评论列表分页 默认 第1页 每页10条记录
             viewmodel.Comments   = GetCommentList(1, 10, out var total, id.Value);
             viewmodel.TotalCount = total;
             return(View(viewmodel));
         }
     }
     return(NotFound());
 }
コード例 #2
0
ファイル: CommentService.cs プロジェクト: mdybich/Apollo
        public CommentListViewModel GetComments(int albumId)
        {
            var album = _db.Albums.SingleOrDefault(a => a.Id == albumId);

            if (album == null)
            {
                throw new Exception("Can not find album!");
            }

            var comments =
                _db.Comments
                .Where(c => c.AlbumId == albumId)
                .OrderByDescending(c => c.DateAdded)
                .ToList()
                .Select(c => new CommentViewModel()
            {
                Id           = c.Id,
                UserFullName = $"{c.User.FirstName} {c.User.LastName}",
                Content      = c.Content,
                DateAdded    = c.DateAdded.ToShortDateString()
            });

            var commentList = new CommentListViewModel()
            {
                AlbumId    = album.Id,
                AlbumName  = album.Name,
                ArtistName = album.Artist.Name,
                Comments   = comments.ToList()
            };

            return(commentList);
        }
コード例 #3
0
ファイル: LotController.cs プロジェクト: KaplinSergey/Auction
 public ActionResult GetCommentsList(CommentListViewModel model)
 {
     if (ModelState.IsValid)
     {
         UserEntity    currentUser = _userService.GetUserByEmail(User.Identity.Name);
         CommentEntity newComment  = new CommentEntity {
             LotId = model.LotId, Text = model.Text, Date = DateTime.Now, UserId = currentUser.Id
         };
         _commentService.CreateComment(newComment);
         if (!Request.IsAjaxRequest())
         {
             return(RedirectToAction("LotDetails", new { id = model.LotId }));
         }
         else
         {
             model.Comments = _commentService.GetAllCommentEntitiesByLotId(model.LotId).Select(c => c.ToMvcComment()).OrderBy(c => c.Date);
             return(PartialView(model));
         }
     }
     if (!Request.IsAjaxRequest())
     {
         return(RedirectToAction("LotDetails", new { id = model.LotId }));
     }
     else
     {
         model.Comments = _commentService.GetAllCommentEntitiesByLotId(model.LotId).Select(c => c.ToMvcComment()).OrderBy(c => c.Date);
         return(PartialView(model));
     }
 }
コード例 #4
0
ファイル: PostsController.cs プロジェクト: jhapriyanka06/.net
        public ViewResult Comment(int id)
        {
            CommentListViewModel commentlistviewmodel = new CommentListViewModel();

            commentlistviewmodel.comments = _commentRepository.GetAllComments(id);
            return(View(commentlistviewmodel));
        }
コード例 #5
0
        public ViewResult List(string category, int page = 1)
        {
            ViewBag.SeletedCategory = category;
            CommentListViewModel model = new CommentListViewModel
            {
                Comments = repository.Comments
                           .Where(p => category == null || p.Category == category)
                           .OrderBy(p => p.Date)
                           .Skip((page - 1) * PageSize)
                           .Take(PageSize),

                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = category == null?repository.Comments.Count() :
                                       repository.Comments.Where(e => e.Category == category).Count()
                },

                CurrentCategory = category,

                Categories = Tongji.getCategories()
            };

            return(View(model));
        }
コード例 #6
0
        // GET: Comments
        public PartialViewResult List(int recipeId, bool owner)
        {
            List <CommentViewModel> comments = (_repo.GetComments())
                                               .ProjectTo <CommentViewModel>()
                                               .Where(s => s.RecipeId == recipeId)
                                               .OrderBy(s => s.PostTime)
                                               .ToList();

            if (!owner)
            {
                comments = comments.Where(o => o.IsDeleted == false).ToList();
            }

            if (comments == null)
            {
                comments = new List <CommentViewModel>();
            }
            comments.Add(new CommentViewModel());

            CommentListViewModel vm = new CommentListViewModel()
            {
                Items    = comments,
                RecipeId = recipeId,
                Owner    = owner
            };

            return(PartialView("List", vm));
        }
コード例 #7
0
        public async Task GetRequest_ReturnsAModelWithCorrectNumberOfComments()
        {
            TestableCommentController controller = TestableCommentController.Create();

            controller.CommentRepository.CommentAggregates.Add(new CommentAggregate());
            controller.CommentRepository.CommentAggregates.Add(new CommentAggregate());
            controller.CommentRepository.CommentAggregates.Add(new CommentAggregate());

            var model = new CommentListViewModel {
                CountdownId = 123,
                Token       = 123,
                Page        = 5
            };

            JsonResult result = await controller.Index(model) as JsonResult;

            Assert.IsNotNull(result);

            CommentListViewModel resultModel = result.Data as CommentListViewModel;

            Assert.IsNotNull(resultModel);
            Assert.AreEqual(3, resultModel.Comments.Count());
            Assert.AreEqual(3, resultModel.Total);
            Assert.AreEqual(model.Page, resultModel.Page);
            Assert.AreEqual(model.Token, resultModel.Token);
            Assert.AreEqual(model.DisplayOrderType, resultModel.DisplayOrderType);
        }
コード例 #8
0
ファイル: CommentController.cs プロジェクト: n1ghtmare/Kauntr
        public async Task <ActionResult> Index(CommentListViewModel model)
        {
//            await Task.Delay(3000);

            Task <int> count = _commentRepository.GetTotalCountAsync(model.CountdownId);
            Task <IEnumerable <CommentAggregate> > aggregates = _commentRepository.GetAggregatesAsync(new CommentFilter {
                CountdownId          = model.CountdownId,
                Page                 = model.Page,
                Limit                = CommentLimit,
                CurrentUserAccountId = _contextService.CurrentUserAccountId,
                DisplayOrderType     = model.DisplayOrderType
            });

            await Task.WhenAll(count, aggregates);

            var result = new CommentListViewModel {
                Total            = await count,
                Comments         = (await aggregates).ToCommentViewModels(),
                Page             = model.Page,
                CountdownId      = model.CountdownId,
                DisplayOrderType = model.DisplayOrderType,
                Token            = model.Token
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #9
0
        public ViewResult Index(string category, string subject, string date, bool?marked, bool?followup, int page = 1, string followupDescr = null)
        {
            DateTime filterAfter = CalculateStartTime(date);
            var      comments    = this.Comments();

            if (followupDescr == "")
            {
                followupDescr = null;
            }

            var commentList = comments.Where(p => category == null || p.Category == category)
                              .Where(p => subject == null || p.Subject == subject || p.Category == subject || subject == "Alle categorieën en onderwerpen")
                              .Where(p => p.UpdatedDate > filterAfter)
                              .Where(p => marked == null || marked == false || p.IsMarked == (bool)marked || (p.IsComment == false && p.HasMarkedComment))
                              .Where(p => followup == null || followup == false || p.IsFollowUp == (bool)followup)
                              .Where(p => followupDescr == null || followupDescr == p.FollowUpRole || (followupDescr == "Medewerker" && p.FollowUpRole.Contains("Medewerker")) || (followupDescr == "MijnOpvolgingen" && p.FollowUpName == Convert.ToString(Session["username"])))
                              .ToList();

            var startPage = commentList.Where(i => i.IsComment == false).ElementAtOrDefault((page - 1) * PageSize);
            var endPage   = commentList.Where(i => i.IsComment == false).ElementAtOrDefault((page) * PageSize);

            int startPageIndx = 0;
            int totalTaken    = commentList.Count();

            if (startPage != null)
            {
                startPageIndx = commentList.IndexOf(startPage);
                if (endPage != null)
                {
                    totalTaken = (commentList.IndexOf(endPage) - startPageIndx);
                }
            }

            int    nrMessages = commentList.Where(i => i.IsComment == false).Count();
            double totalPages = Convert.ToDouble(nrMessages) / Convert.ToDouble(PageSize);

            CommentListViewModel model = new CommentListViewModel()
            {
                CommentList = commentList
                              .Skip(startPageIndx)
                              .Take(totalTaken)
                              .ToList(),
                SearchData = new SearchInfo
                {
                    CurrentCategory = category,
                    CurrentSubject  = subject,
                    CurrentDate     = date,
                    CurrentFollowup = followup,
                    CurrentMarked   = marked
                },
                PagingData = new PagingInfo
                {
                    CurrentPage = page,
                    TotalPages  = (int)Math.Ceiling(totalPages)
                }
            };

            return(View(model));
        }
コード例 #10
0
        // GET: /Comments
        public virtual ActionResult CommentList(int taskId)
        {
            var commentFilter = new CommentFilter().ByTask(taskId);
            var comments = CommentService.GetAll(Query.ForComment(commentFilter).Include(x => x.Employee()));

            var model = new CommentListViewModel { Comments = comments, TaskId = taskId };
            return PartialView(MVC.Comments.Views._ListComment, model);
        }
コード例 #11
0
ファイル: LotController.cs プロジェクト: KaplinSergey/Auction
        public PartialViewResult GetCommentsList(int lotId)
        {
            IEnumerable <CommentViewModel> comments = _commentService.GetAllCommentEntitiesByLotId(lotId).Select(c => c.ToMvcComment()).OrderBy(c => c.Date);
            CommentListViewModel           model    = new CommentListViewModel {
                Comments = comments, LotId = lotId
            };

            return(PartialView(model));
        }
コード例 #12
0
        public IViewComponentResult Invoke(int articleId)
        {
            CommentListViewModel commentListViewModel = new CommentListViewModel();
            var commentList = _commentManager.LoadEntities(x => x.ArticleId == articleId).ToList();

            commentListViewModel.ArticleId = articleId;
            commentListViewModel.List      = commentList;
            return(View("CommentList", commentListViewModel));
        }
コード例 #13
0
        public async Task <IActionResult> List(int pageindex = 1)
        {
            var VM = new CommentListViewModel(ce);

            VM.comments = await cms.GetPageListAsync(pageindex, 10);

            VM.pageindex = pageindex;

            return(View(VM));
        }
コード例 #14
0
        public async Task <IActionResult> IndexComments(int?bookId, int pageNum = 1)
        {
            var book = await _bookManager.GetBookByIdAsync(bookId.Value);

            var comments = (await _commentService.GetCommentsAsync(pageNum, bookId.Value)).ToList();

            string userId = (await _currentUser.GetCurrentUser(HttpContext)).Id;
            CommentListViewModel bookComment = new CommentListViewModel(book.Title, book.Id, comments.Any(p => p.AppUserId == userId),
                                                                        pageNum, PageSizes.Comments, comments.Count(), comments);

            return(View(bookComment));
        }
コード例 #15
0
        public async Task <ActionResult> ListAjax(CommentSearchRequest search)
        {
            var comments = await _commentService.GetPagedListAsync(search);

            var viewModel = new CommentListViewModel
            {
                Comments      = comments.Comments,
                SearchRequest = search
            };

            return(PartialView("_ListAjax", viewModel));
        }
コード例 #16
0
        public IViewComponentResult Invoke(int?postId)
        {
            var model = new CommentListViewModel
            {
                Comments = _commentManager.GetByPost((int)postId)
            };

            return(View(model));
            //IstanbulTGContext context = new IstanbulTGContext();
            //var yorumlar = context.Comments.ToList();
            //return View(_commentManager.GetByPost((int)postId));
            //return View(yorumlar);
        }
コード例 #17
0
ファイル: CommentController.cs プロジェクト: tomkecy/BlogApp
        public PartialViewResult List(int id)
        {
            CommentListViewModel model = new CommentListViewModel()
            {
                NewComment = new PostComment()
                {
                    PostId = id
                },
                PostComments = postRepository.GetById(id).PostComments
            };

            return(PartialView(model));
        }//END of List method
コード例 #18
0
        private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            String tag = (String)((FrameworkElement)sender).Tag;

            rlvm = new CommentListViewModel(pvm.permalink, tag);
            Binding b = new Binding();

            b.Source = rlvm.Comments;
            b.Mode   = BindingMode.OneWay;
            RepliesListView.SetBinding(ListView.ItemsSourceProperty, b);
            RepliesListView.Width  = ApplicationView.GetForCurrentView().VisibleBounds.Width - 100;
            RepliesListView.Height = ApplicationView.GetForCurrentView().VisibleBounds.Height - 150;
            RepliesPanel.IsOpen    = true;
        }
コード例 #19
0
        public ActionResult GetCommentListByOrderId(long id, string orderType, long orderid)
        {
            var pager = new Pager {
                PageSize = Configinfo.CommentPagerCount
            };

            pager = MyService.GetFloorCommentPagingByOrderId(pager, id, orderid, orderType);
            var commentListViewModel = new CommentListViewModel
            {
                CommentPagerInfo = pager
            };

            return(PartialView("_CommentList", commentListViewModel));
        }
コード例 #20
0
        public ActionResult UserCommentList(int p, int size = 20)
        {
            var pager = new Pager {
                PageNo = p, PageSize = size
            };

            pager = MyService.GetReplyPaging(pager, 1, 0, user: UserInfo.userid);
            var commentListViewModel = new CommentListViewModel
            {
                CommentPagerInfo = pager
            };

            return(PartialView("_UserComment", commentListViewModel));
        }
コード例 #21
0
        public CommentListViewModel GetAllComments()
        {
            var vm = new CommentListViewModel
            {
                Comments = _context.PostComments.Select(x => new CommentListItemViewModel
                {
                    Id            = x.Id,
                    Title         = x.Title,
                    Content       = x.Content,
                    CommentAuthor = x.CommentAuthor
                })
            };

            return(vm);
        }
コード例 #22
0
        public ActionResult CommentList(long id, string orderType, int?p)
        {
            var pageNo = (p ?? 1) > 0 ? (p ?? 1) : 1;
            var pager  = new Pager {
                PageNo = pageNo, PageSize = Configinfo.CommentPagerCount
            };

            pager = MyService.GetFloorCommentPaging(pager, id, orderType);
            var commentListViewModel = new CommentListViewModel
            {
                CommentPagerInfo = pager
            };

            return(PartialView("_CommentList", commentListViewModel));
        }
コード例 #23
0
        public ViewResult Comment(Book book)
        {
            IEnumerable <Comment> comments = null;
            Book _book = book;

            comments = _allComment.Comments.Where(i => i.Book.ID == i.ID).OrderBy(i => i.ID);

            var commObj = new CommentListViewModel
            {
                Comments = comments,
                Book     = _book
            };

            return(View(commObj));
        }
コード例 #24
0
        //
        // GET: Comment/List
        public ActionResult List(int?articleId, int page = 1)
        {
            if (articleId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (var database = new BlogDbContext())
            {
                var article = database.Articles
                              .Where(a => a.Id == articleId)
                              .Include(a => a.Author)
                              .FirstOrDefault();

                if (article == null)
                {
                    return(HttpNotFound());
                }

                // Set the paging
                if (page < 1)
                {
                    page = 1;
                }

                var pageSize = 2;

                var comments = article.Comments
                               .OrderByDescending(c => c.DateCreated)
                               .Skip((page - 1) * pageSize)
                               .Take(pageSize)
                               .ToList();

                var model = new CommentListViewModel()
                {
                    ArticleAuthorId   = article.AuthorId,
                    ArticleAuthorName = article.Author.FullName,
                    ArticleDate       = article.DateCreated,
                    ArticleId         = article.Id,
                    ArticleTitle      = article.Title,
                    Comments          = comments,
                    CurrentPage       = page,
                    PagesCount        = (int)Math.Ceiling(article.Comments.Count * 1.0 / pageSize)
                };

                return(View(model));
            }
        }
コード例 #25
0
        public ActionResult SaveComment(CommentListViewModel vm)
        {
            foreach (CommentViewModel item in vm.Items)
            {
                Comment e = Mapper.Map <CommentViewModel, Comment>(item);
                if (e.Id == 0)
                {
                    // _repo.in(e);
                }
                else
                {
                    _repo.UpdateComment(e);
                }
            }

            return(RedirectToAction("details", new { id = vm.RecipeId }));
        }
コード例 #26
0
        public void CanReturnProperModel()
        {
            //Arrange
            CommentController target = new CommentController(_postRepositoryMock.Object);

            //Act
            CommentListViewModel result = (CommentListViewModel)target.List(1).Model;


            //Assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual(result.NewComment.PostId, 1);
                Assert.True(result.PostComments.Count() == 5);
            }
                            );
        }//END of CanReturnProperModel method
コード例 #27
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            pvm  = (PostViewModel)e.Parameter;
            clvm = new CommentListViewModel(pvm.permalink, pvm.id);
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame.CanGoBack)
            {
                // Show UI in title bar if opted-in and in-app backstack is not empty.
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    AppViewBackButtonVisibility.Visible;
            }
            else
            {
                // Remove the UI from the title bar if in-app back stack is empty.
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    AppViewBackButtonVisibility.Collapsed;
            }
        }
コード例 #28
0
        public ActionResult Index(int page = 1)
        {
            var       user    = (UserViewModel)Session["CurrentUser"];
            WSRequest request = new WSRequest("users/" + user.IdUser + "/posts/comments?page=" + page);

            request.AddAuthorization(Session["token"].ToString());
            var response = request.Get();

            if (response.Code != 200)
            {
                return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar esse post" }));
            }

            var body = response.Body;
            CommentListViewModel model = new CommentListViewModel();
            var pagination             = body.GetValue("pagination");

            model.Pagination = new PaginationViewModel
            {
                NextPage         = (bool)pagination["next_page"],
                PreviousPage     = (bool)pagination["previous_page"],
                CurrentPage      = (int)pagination["current_page"],
                TotalNumberPages = (int)pagination["total_number_pages"],
            };
            model.Comments = new List <CommentViewModel>();
            foreach (var comment in body.GetValue("comments"))
            {
                model.Comments.Add(
                    new CommentViewModel
                {
                    IdComment  = (int)comment["id_comment"],
                    IdPost     = (int)comment["id_post"],
                    Content    = comment["content"].ToString(),
                    IdUser     = (int)comment["id_user"],
                    ApprovedAt = comment["approved_at"].ToString(),
                    CreatedAt  = comment["created_at"].ToString()
                }
                    );
            }

            return(View(model));
        }
        //
        // GET: /Comment/
        public ActionResult Index(int id)
        {
            var commentsRepository = new CommentsRepository();
            var commentsList       = new List <Comment>();

            var commentsFromRepo = commentsRepository.GetAll(comment => comment.AssignmentId == id);

            // var commentsFromRepo = commentsRepository.GetAll();
            //foreach (var comment in commentsFromRepo)
            //{
            //    if (comment.AssignmentId == id)
            //    {
            //        commentsList.Add(comment);
            //    }
            //}

            commentsList.AddRange(commentsFromRepo);

            var assignmentRepository = new AssignmentRepository();

            var model = new CommentListViewModel();

            model.AssignmentTitle = assignmentRepository.GetById(id).Title;
            model.AssignmentId    = id;

            foreach (var entity in commentsList)
            {
                var commentModel = new CommentViewModel()
                {
                    Id           = entity.Id,
                    AssignmentId = entity.AssignmentId,
                    Content      = entity.Content,
                    CreatedAt    = entity.CreatedAt,
                    UpdatedAt    = entity.UpdatedAt
                };

                model.Comments.Add(commentModel);
            }


            return(View(model));
        }
コード例 #30
0
        public async Task GetRequest_ReturnsCommentListViewModel()
        {
            TestableCommentController controller = TestableCommentController.Create();
            var model = new CommentListViewModel {
                CountdownId = 123,
                Token       = 123,
                Page        = 1
            };

            JsonResult result = await controller.Index(model) as JsonResult;

            Assert.IsNotNull(result);

            CommentListViewModel resultModel = result.Data as CommentListViewModel;

            Assert.IsNotNull(resultModel);
            Assert.AreEqual(model.CountdownId, resultModel.CountdownId);
            Assert.AreEqual(model.Token, resultModel.Token);
            Assert.AreEqual(model.Page, resultModel.Page);
        }
コード例 #31
0
        public ActionResult AddComment(CommentListViewModel vm)
        {
            foreach (CommentViewModel item in vm.Items)
            {
                Comment e = Mapper.Map <CommentViewModel, Comment>(item);
                e.RecipeId = vm.RecipeId;
                e.UserId   = User.UserId;
                e.PostTime = DateTime.Now;
                if (e.Id == 0)
                {
                    _repo.InsertComment(e);
                }
                else
                {
                    //_repo.UpdateComment(e);
                }
            }

            return(RedirectToAction("details", new { id = vm.RecipeId }));
        }