Ejemplo n.º 1
0
 public PartialViewResult DisplayAddComment(int id)
 {
     try
     {
         User_News_Comments unc = new User_News_Comments();
         unc.news = db.news.Find(id);
         return(PartialView("~/Views/news_partials/_AddComment.cshtml", unc));
     }
     catch (Exception e)
     {
         ViewBag.GenericException = e.Message;
     }
     return(PartialView("~/Views/Shared/_ErrorMssg.cshtml"));
 }
Ejemplo n.º 2
0
        public ActionResult DisplayComments(int id)
        {
            try
            {
                //PULL COMMENTS FROM ARTICLE ID, AND EACH USER.
                var comments = (from n in db.news
                                join c in db.comments on n.id equals c.article_id
                                join u in db.users on c.user_id equals u.id
                                where n.id == id
                                orderby c.comm_date descending
                                select new
                {
                    c,
                    u
                });

                List <User_News_Comments> uncL = new List <User_News_Comments>();
                foreach (var comment in comments)
                {
                    User_News_Comments unc = new User_News_Comments();
                    unc.user    = comment.u;
                    unc.comment = comment.c;
                    unc.news    = db.news.Find(id);
                    uncL.Add(unc);
                }
                return(PartialView("~/Views/news_partials/_displayComments.cshtml", uncL));
            }
            catch (DbUpdateException e)
            {
                ViewBag.DbExceptionMessage = e.Message;
            }
            catch (SqlException e)
            {
                ViewBag.SqlExceptionMessage = e.Message;
            }
            catch (Exception e)
            {
                ViewBag.GenericException = e.Message;
            }
            return(RedirectToAction("Errors", "Navigate"));
        }
Ejemplo n.º 3
0
        //AJAX ADDING A COMMENT
        public PartialViewResult AddComment(int id, User_News_Comments unc)
        {
            if (unc.comment.comment1 != null)
            {
                try
                {
                    //ADD INTO THE COMMENTS TABLE
                    comment comment = new comment();

                    if (Session["userId"] != null)
                    {
                        comment.user_id = Convert.ToInt16(Session["userId"]);
                    }
                    else
                    {
                        RedirectToAction("Details", new { id });
                    }
                    comment.article_id = id;
                    comment.comm_date  = DateTime.Now;
                    comment.comment1   = unc.comment.comment1.Trim();
                    db.comments.Add(comment);
                    db.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    ViewBag.ErrorMssg = e.Message;
                    return(PartialView("~/Views/Shared/_ErrorMssg.cshtml"));
                }
                catch (SqlException e)
                {
                    ViewBag.ErrorMssg = e.Message;
                    return(PartialView("~/Views/Shared/_ErrorMssg.cshtml"));
                }
                catch (Exception e)
                {
                    ViewBag.ErrorMssg = e.Message;
                    return(PartialView("~/Views/Shared/_ErrorMssg.cshtml"));
                }
            }
            //PULL COMMENTS FROM ARTICLE ID, AND EACH USER.
            var comments = (from n in db.news
                            join c in db.comments on n.id equals c.article_id
                            join u in db.users on c.user_id equals u.id
                            where n.id == id
                            orderby c.comm_date descending
                            select new
            {
                c,
                u
            });

            List <User_News_Comments> uncL = new List <User_News_Comments>();

            foreach (var comm in comments)
            {
                User_News_Comments user_n_c = new User_News_Comments();
                user_n_c.user    = comm.u;
                user_n_c.comment = comm.c;
                user_n_c.news    = db.news.Find(id);
                uncL.Add(user_n_c);
            }
            return(PartialView("~/Views/news_partials/_displayComments.cshtml", uncL));
        }