Beispiel #1
0
 public ActionResult AddComment(NewsAndComments comments)
 {
     if (Session["LoginUserID"] != null)
     {
         using (UnitOfWork unit = new UnitOfWork())
         {
             UserRepository userRep = new UserRepository(unit.DataContext);
             NewsRepository newsRep = new NewsRepository(unit.DataContext);
             CommentRepository comRep = new CommentRepository(unit.DataContext);
             //News news = newsRep.GetNewsById(id);
             User user = userRep.GetUserById(new Guid((Session["LoginUserID"]).ToString()));
             CommentService comServ = new CommentService(unit.DataContext);
             comments.News = newsRep.GetNewsById(new Guid((Session["NewsId"]).ToString()));
             //comments.News.Comments = comRep.GetCommentsByPublicationId(new Guid((Session["NewsId"]).ToString())).ToList();
             //comments.News.Owner = user;
             comServ.Create(user, comments.News, comments.CurrentComment);
             unit.Commit();
             comments.Comments = newsRep.GetNewsById(comments.News.NewsId).Comments;
         }
     }
     if (Request.IsAjaxRequest())
     {
         return PartialView("_GridForComments", comments);
     }
     return RedirectToAction("ReadMore/" + comments.News.NewsId.ToString());
 }
Beispiel #2
0
        public ActionResult ReadMore(Guid id)
        {
            NewsAndComments newsAndComms = new NewsAndComments();
            IEnumerable<Comment> comments = null;
            using (UnitOfWork unit = new UnitOfWork())
            {
                NewsRepository newsRep = new NewsRepository(unit.DataContext);
                News news = newsRep.GetNewsById(id);
                CommentRepository comRep = new CommentRepository(unit.DataContext);
                comments = comRep.GetCommentsByPublicationId(id);
                newsAndComms.News = news;
                newsAndComms.Comments = comments;
                Session["NewsId"] = news.NewsId;
            }

            return View(newsAndComms);
        }
Beispiel #3
0
        public ActionResult DeleteComm(Guid id)
        {
            if (Session["LoginUserID"] != null)
            {
                using (UnitOfWork unit = new UnitOfWork())
                {
                    CommentRepository comRep = new CommentRepository(unit.DataContext);
                    CommentService comServ = new CommentService(unit.DataContext);
                    NewsAndComments newsAndComments = new NewsAndComments();
                    Guid newsId = new Guid(comRep.GetCommentById(id).Publication.NewsId.ToString());
                    newsAndComments.News = comRep.GetCommentById(id).Publication;

                    if (UserValidator.IsValid(Session["LoginUserID"].ToString(), comRep.GetCommentById(id).Publication.Owner))
                    {
                        comServ.Delete(id);
                        unit.Commit();
                    }

                    newsAndComments.Comments = comRep.GetCommentsByPublicationId(newsId);

                    if (Request.IsAjaxRequest())
                    {
                        return PartialView("_GridForComments", newsAndComments);
                    }
                    else
                    {
                        return View("ReadMore", newsAndComments);
                    }
                }
            }
            return HttpNotFound();
        }