Пример #1
0
        public async Task <IActionResult> Comment(NewsCommentViewModel vm,
                                                  [FromServices] GetOneNews getOneNews,
                                                  [FromServices] CreateComment createComment)
        {
            if (!ModelState.IsValid)
            {
                var singleNews = getOneNews.Do(vm.NewsId);
                return(RedirectToAction("SingleNewsDisplay", new { id = singleNews.Id }));
            }

            var news = getOneNews.Do(vm.NewsId);

            if (vm.NewsMainCommentId == 0)
            {
                await createComment.CreateMainComment(new CreateComment.MainCommentRequest
                {
                    OneNewsId = news.Id,
                    Created   = DateTime.Now,
                    Creator   = "",
                    Message   = vm.Message,
                });
            }
            else
            {
                await createComment.CreateSubComment(new CreateComment.SubCommentRequest
                {
                    NewsMainCommentId = vm.NewsMainCommentId,
                    Created           = DateTime.Now,
                    Creator           = "",
                    Message           = vm.Message,
                });
            }

            return(RedirectToAction("SingleNewsDisplay", new { id = news.Id }));
        }
        public ActionResult DisplayNews(int?DocId)
        {
            if (!DocId.HasValue)
            {
                Response.Redirect("/");
                return(View());
            }
            else
            {
                var item = db.News.Find(DocId.Value);

                var comments = db.CommentsNews
                               .Where(a => a.News.Id == item.Id)
                               .Select(a => new NewsCommentViewModel {
                    Text = a.Text, Author = a.Author
                })
                               .ToList();
                ViewBag.Comments = comments;

                var nComments = comments.Count();

                var surfer = item.Surfers.FirstOrDefault();

                if (surfer != null)
                {
                    var obj1 = new NewsCommentViewModel
                    {
                        DocId       = DocId.Value,
                        Name        = item.Name,
                        Image       = item.Image,
                        Description = item.Description,
                        Location    = item.Location,
                        SurferName  = surfer.Name,
                        NumComments = nComments
                    };
                    return(View(obj1));
                }

                var obj2 = new NewsCommentViewModel
                {
                    DocId       = DocId.Value,
                    Name        = item.Name,
                    Image       = item.Image,
                    Description = item.Description,
                    Location    = item.Location,
                    NumComments = nComments
                };

                return(View(obj2));
            }
        }
Пример #3
0
 /// <summary>
 /// 页面加载
 /// </summary>
 /// <param name="e"></param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (e.NavigationMode == NavigationMode.New)
     {
         News news = (News)e.Parameter;
         NewsCommentViewModel = new NewsCommentViewModel(news);
         NewsCommentViewModel.OnLoadMoreStarted   += count => LoadingProgressRing.IsActive = true;
         NewsCommentViewModel.OnLoadMoreCompleted += count => LoadingProgressRing.IsActive = false;
         NewsCommentViewModel.Refresh();
     }
     //App.NavigationService.DetailFrame.Navigating += (sender, args) => LoadingProgressRing.IsActive = true;
     //App.NavigationService.DetailFrame.Navigated += (sender, args) => LoadingProgressRing.IsActive = false;
     base.OnNavigatedTo(e);
 }
Пример #4
0
 /// <summary>
 /// 页面加载
 /// </summary>
 /// <param name="e"></param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (e.NavigationMode == NavigationMode.New)
     {
         News news = (News)e.Parameter;
         NewsCommentViewModel = new NewsCommentViewModel(news);
         NewsCommentViewModel.OnLoadMoreStarted += count => LoadingProgressRing.IsActive = true;
         NewsCommentViewModel.OnLoadMoreCompleted += count => LoadingProgressRing.IsActive = false;
         NewsCommentViewModel.Refresh();
     }
     //App.NavigationService.DetailFrame.Navigating += (sender, args) => LoadingProgressRing.IsActive = true;
     //App.NavigationService.DetailFrame.Navigated += (sender, args) => LoadingProgressRing.IsActive = false;
     base.OnNavigatedTo(e);
 }
Пример #5
0
        public async Task <IActionResult> CommPart(Guid id)
        {
            var News__    = _unitOfWork.News_.AsQueryable();
            var Comments_ = _unitOfWork.Comments.AsQueryable();

            var news         = News__.Where(p => p.Id.Equals(id)).FirstOrDefault();
            var commentModel = await Comments_.Include("UsersId").Include("News").ToListAsync();

            var comments = commentModel.Where(i => i.News.Id.Equals(id)).OrderBy(o => o.DatePub);

            var newsModel = new NewsCommentViewModel()
            {
                News     = news,
                Comments = comments
            };

            return(PartialView("CommPart", newsModel));
        }
        public ActionResult SetComment(NewsCommentViewModel model)
        {
            if (ModelState.IsValid)
            {
                News Item = db.News.Find(model.DocId);

                var comment = new CommentNews {
                    Author = HttpContext.User.Identity.Name, Text = model.Text, News = Item
                };
                db.CommentsNews.Add(comment);
                var result = db.SaveChanges();

                if (result > 0)
                {
                    return(RedirectToAction("DisplayNews", "News", new { DocId = Item.Id }));
                }
            }
            return(View(model));
        }
Пример #7
0
 public RedirectToRouteResult CommentCreate(NewsCommentViewModel model)
 {
     NewsComment comment = new NewsComment();
     comment.Author = Membership.GetUser().UserName;
     comment.Date = DateTime.Now;
     comment.Text = model.Text;
     if (ModelState.IsValid)
     {
         //int NewsID = Int32.Parse(values["NewsID"]);
         var news = db.News.Find(model.NewsID);
         news.NewsComments.Add(comment);
         db.SaveChanges();
     }
     else
     {
         ViewBag.CommentError = "Błąd! Komentarza nie dodano.";
     }
     return RedirectToAction("Details", new { ID = model.NewsID });
 }