예제 #1
0
        public ActionResult SingleUserPost(int?id)
        {
            if (Session["Adminid"] == null)
            {
                return(RedirectToAction("Login"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            UserPost userpost = db.Post.Find(id);

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

            //send user basic info to profile

            ViewBag.UserPost = userpost;



            // commenter name and image

            var joinimage = (from usr in db.Users
                             join cmnt in db.Comments on usr.UserId equals cmnt.UserId
                             where cmnt.PostId == id
                             select new
            {
                usr.Name,
                usr.Image,
                cmnt.UserComment,
                cmnt.Time
            }).ToList();
            List <UserJoinComment> aJoinCommentList = new List <UserJoinComment>();


            {
                foreach (var v in joinimage)
                {
                    UserJoinComment aJoinComment = new UserJoinComment();

                    aJoinComment.Comment       = v.UserComment;
                    aJoinComment.CommenterName = v.Name;
                    aJoinComment.Image         = v.Image;
                    aJoinComment.Time          = v.Time;
                    aJoinCommentList.Add(aJoinComment);
                    ViewData["CommentsData"] = aJoinCommentList;
                }
            }



            return(View());
        }
예제 #2
0
        //Single PostDetails Details
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Session["PostId"] = Convert.ToInt32(id);

            UserPost userpost = db.Post.Find(id);

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

            //send user basic info to profile

            ViewBag.UserPost = userpost;

            int postid = Convert.ToInt32(Session["PostId"]);



            //join value of comenter pic and comment

            var joinimage = (from usr in db.Users
                             join cmnt in db.Comments on usr.UserId equals cmnt.UserId
                             where cmnt.PostId == postid
                             select new
            {
                usr.Name,
                usr.Image,
                cmnt.UserComment,
                cmnt.Time
            }).ToList();
            List <UserJoinComment> aJoinCommentList = new List <UserJoinComment>();


            {
                foreach (var v in joinimage)
                {
                    UserJoinComment aJoinComment = new UserJoinComment();

                    aJoinComment.Comment       = v.UserComment;
                    aJoinComment.CommenterName = v.Name;
                    aJoinComment.Image         = v.Image;
                    aJoinComment.Time          = v.Time;
                    aJoinCommentList.Add(aJoinComment);
                    ViewData["CommentsData"] = aJoinCommentList;
                }
            }



            return(View());
        }
예제 #3
0
        public ActionResult UserSinglePostDetails(Comment aComment)
        {
            if (Session["Author"] == null)
            {
                return(RedirectToAction("Login", "Registration"));
            }


            int postid = Convert.ToInt32(Session["PostId"]);

            // commenter name and image

            var joinimage = (from usr in db.Users
                             join cmnt in db.Comments on usr.UserId equals cmnt.UserId
                             where cmnt.PostId == postid
                             select new
            {
                usr.Name,
                usr.Image,
                cmnt.UserComment,
                cmnt.Time
            }).ToList();
            List <UserJoinComment> aJoinCommentList = new List <UserJoinComment>();


            {
                foreach (var v in joinimage)
                {
                    UserJoinComment aJoinComment = new UserJoinComment();

                    aJoinComment.Comment       = v.UserComment;
                    aJoinComment.CommenterName = v.Name;
                    aJoinComment.Image         = v.Image;
                    aJoinComment.Time          = v.Time;
                    aJoinCommentList.Add(aJoinComment);
                    ViewData["CommentsData"] = aJoinCommentList;
                }
            }



            aComment.UserId   = Convert.ToInt32(Session["UserId"]);
            aComment.UserName = Session["Author"].ToString();
            aComment.PostId   = Convert.ToInt32(Session["PostId"]);
            aComment.Time     = DateTime.Now;

            if (ModelState.IsValid)
            {
                db.Comments.Add(aComment);
                db.SaveChanges();
                return(RedirectToAction("UserSinglePostDetails"));
            }

            return(View(aComment));
        }