コード例 #1
0
 public ActionResult ideaDetail(int obj)
 {
     if (Session["UserID"] != null)
     {
         int sID             = (int)Session["UserID"];
         DatabaseEntities db = new DatabaseEntities();
         PostTable        pt = db.PostTables.Find(obj);
         if (pt.post_userID == sID)
         {
             return(RedirectToAction("EditIdea", "Home", new { id = obj }));
         }
         else
         {
             ideaDetail data = new ideaDetail();
             data.postData = pt;
             data.userData = db.UserTables.Where(r => r.user_Id == pt.post_userID).FirstOrDefault();
             List <commentTable>  comment = db.commentTables.Where(r => r.comment_postID == pt.post_Id).ToList();
             List <commentDetail> cmList  = new List <commentDetail>();
             foreach (var a in comment)
             {
                 commentDetail cmntdetail = new commentDetail();
                 cmntdetail.cmnt = a;
                 cmntdetail.user = db.UserTables.Find(a.comment_userID);
                 cmList.Add(cmntdetail);
             }
             data.commentData = cmList;
             data.likeData    = db.LikesTables.Where(r => r.like_postID == pt.post_Id).ToList();
             return(View(data));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Home"));
     }
 }
コード例 #2
0
        public ActionResult EditIdea(int id)
        {
            DatabaseEntities db   = new DatabaseEntities();
            PostTable        obj  = db.PostTables.Find(id);
            ideaDetail       data = new ideaDetail();

            data.postData = obj;
            data.userData = db.UserTables.Where(r => r.user_Id == obj.post_userID).FirstOrDefault();
            List <commentTable>  comment = db.commentTables.Where(r => r.comment_postID == obj.post_Id).ToList();
            List <commentDetail> cmList  = new List <commentDetail>();

            foreach (var a in comment)
            {
                commentDetail cmntdetail = new commentDetail();
                cmntdetail.cmnt = a;
                cmntdetail.user = db.UserTables.Find(a.comment_userID);
                cmList.Add(cmntdetail);
            }
            data.commentData = cmList;
            data.likeData    = db.LikesTables.Where(r => r.like_postID == obj.post_Id).ToList();
            return(View(data));
        }