Exemple #1
0
        public void TestFollowUser()
        {
            //Arrange
            var  controller = new CommunicationControllerTest();
            User cur1       = new User
            {
                UserName = "******",
                Password = "******"
            };
            User cur2 = new User
            {
                UserName = "******",
                Password = "******"
            };

            UserDal usrd     = new UserDal();
            User    cur1_Obj = usrd.Users.SingleOrDefault(b => b.UserName == cur1.UserName);
            User    cur2_Obj = usrd.Users.SingleOrDefault(b => b.UserName == cur2.UserName);

            CommentDal cmtd        = new CommentDal();
            Comment    testComment = new Comment()
            {
                commentContent = "Testing Comment 1122334455",
                userId         = cur2_Obj.id,
                threadId       = 1
            };

            cmtd.Comments.Add(testComment);
            cmtd.SaveChanges();
            Comment testId = cmtd.Comments.SingleOrDefault(b => b.commentContent == testComment.commentContent);

            //Act
            controller.follow(testId.commentId, cur1_Obj);

            //Assert
            FollowDal     fdal = new FollowDal();
            List <Follow> f    =
                (from x in fdal.Follows
                 where x.follower == cur1_Obj.id && x.followOn == cur2_Obj.id
                 select x).ToList();

            Assert.IsTrue(f.Any());

            //Clean Up
            cmtd.Comments.Remove(testId);
            cmtd.SaveChanges();

            fdal.Follows.Remove(f[0]);
            fdal.SaveChanges();
        }
Exemple #2
0
        //Action result for deleting a thread
        public ActionResult DeleteThread()
        {
            ThreadDal  td = new ThreadDal();
            CommentDal cd = new CommentDal();
            Thread     t1, t2;

            string id = Request.Params
                        .Cast <string>()
                        .Where(p => p.StartsWith("button"))
                        .Select(p => p.Substring("button".Length))
                        .First();
            int i = Int32.Parse(id);

            t1 = (Thread)Thread_list[i];
            t2 = (from x in td.Threads where t1.ID == x.ID select x).FirstOrDefault();
            td.Threads.Remove(t2);
            td.SaveChanges();

            List <Comment> comments = (from x in cd.Comments where x.ThreadID == t1.ID select x).ToList();

            if (comments != null)
            {
                foreach (Comment comment in comments)
                {
                    cd.Comments.Remove(comment);
                }
                cd.SaveChanges();
                message = "Thread successfully deleted";
            }
            return(RedirectToAction("Threads"));
        }
Exemple #3
0
        //Action result for posting new comment
        public ActionResult post_comment()
        {
            //make comment
            Comment c = new Comment()
            {
                ThreadID = Int32.Parse(Request.Form["t_id"].ToString()),
                Author   = ((SuperUser)Session["user"]).Username,
                Body     = Request.Form["body_cmnt"].ToString(),
                time     = DateTime.Now
            };

            //post comment on sql
            CommentDal cdal = new CommentDal();

            cdal.Comments.Add(c);
            cdal.SaveChanges();

            //order the comment list
            List <Comment> f = cdal.Comments.ToList <Comment>();

            f.OrderBy(x => x.time.TimeOfDay).ToList();
            Comment_list = new ArrayList(f);

            //set the bag again
            ViewBag.Comments = Comment_list;

            //resend the view with the model
            return(View("ThreadPage", current_thread));
        }
        public JsonResult getComment()
        {
            Comment comment = new Comment();

            comment.email     = Request.Form["email"];
            comment.message   = Request.Form["message"];
            comment.date      = DateTime.Now;
            comment.idReceips = Request.Form["recipesId"];
            comment.id        = Hashing.HashPassword(new Random().Next(12023, 132023).ToString());
            CommentDal commentDal = new CommentDal();

            commentDal.Comments.Add(comment);
            commentDal.SaveChanges();
            return(Json(new { statut = true }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteComment()
        {
            if (Session["Log"] == null)
            {
                ViewBag.Error = "not logged";
                return(View("~/Views/Home/NotLogged.cshtml"));
            }

            CommentDal ud   = new CommentDal();
            Comment    test = new Comment()
            {
                id = Request.Form["id"].ToString()
            };
            var customer = ud.Comments.Single(o => o.id == test.id);

            ud.Comments.Remove(customer);
            ud.SaveChanges();

            return(null);
        }
Exemple #6
0
        public ActionResult addLike(String i)
        {
            TempData["canLike"] = true;
            Thread      trd  = (Thread)TempData["CurrentThread"];
            int         id   = (int)TempData["CurrentId" + i];
            Comment     cmt  = (Comment)TempData["CurrentCmt" + i];
            LikeDal     ldal = new LikeDal();
            List <Like> lk   = new List <Like>();

            try
            {
                lk =
                    (from x in ldal.Likes
                     where x.threadId == trd.ThreadId && x.commentId == cmt.commentId && x.usrId == id
                     select x).ToList <Like>();
            }
            catch
            {
            }

            if (lk.Any())
            {
                TempData["canLike"] = 0;

                ldal.Likes.Remove(lk[0]);
                ldal.SaveChanges();

                UserDal     dal   = new UserDal();
                List <User> Users = new List <User>();

                try
                {
                    Users =
                        (from x in dal.Users
                         where x.id == id
                         select x).ToList <User>();
                }
                catch
                {
                }


                int powRate = (Users[0].Likes / 10000) + 1;


                CommentDal     cdal = new CommentDal();
                List <Comment> com  = new List <Comment>();

                try
                {
                    com =
                        (from x in cdal.Comments
                         where x.threadId == trd.ThreadId && x.commentId == cmt.commentId
                         select x).ToList <Comment>();
                }
                catch
                {
                }


                for (int idx = 0; idx < powRate; idx++)
                {
                    com[0].rank--;
                    refreshLikes(cmt.userId, false);
                }
                cdal.SaveChanges();
            }
            else
            {
                if (!canLike(id))
                {
                    TempData["canLike"] = -1;
                }
                else
                {
                    TempData["canLike"] = 0;

                    Like tmplk = new Like()
                    {
                        commentId = cmt.commentId,
                        threadId  = trd.ThreadId,
                        usrId     = id
                    };
                    ldal.Likes.Add(tmplk);
                    ldal.SaveChanges();

                    UserDal        dal   = new UserDal();
                    CommentDal     cdal  = new CommentDal();
                    List <User>    Users = new List <User>();
                    List <Comment> com   = new List <Comment>();

                    try
                    {
                        Users =
                            (from x in dal.Users
                             where x.id == id
                             select x).ToList <User>();
                    }
                    catch
                    {
                    }


                    int powRate = (Users[0].Likes / 10000) + 1;

                    try
                    {
                        (from x in cdal.Comments
                         where x.threadId == trd.ThreadId && x.commentId == cmt.commentId
                         select x).ToList <Comment>();
                    }
                    catch
                    {
                    }


                    for (int idx = 0; idx < powRate; idx++)
                    {
                        com[0].rank++;
                        refreshLikes(cmt.userId, true);
                    }
                    cdal.SaveChanges();
                }
            }
            return(RedirectToAction("ContentPage", "MainPage", trd));
        }
Exemple #7
0
        public void TestNewComment()
        {
            //Arragne
            var    controller = new MainPageControllerTest();
            string content    = "Test Content TESTING!!!!";
            Syear  inst       = new Syear
            {
                SyearId = 1
            };
            User cur = new User
            {
                UserName = "******",
                Password = "******"
            };
            Thread test_Thread = new Thread
            {
                ThreadName = testingThreadHeader,
                SyearId    = 1,
                ThreadType = "[Question]",
                OwnerId    = 1
            };

            ThreadDal tDal = new ThreadDal();

            tDal.Threads.Add(test_Thread); // Add test thread
            tDal.SaveChanges();

            Thread currenthread = tDal.Threads.SingleOrDefault(b => b.ThreadName == testingThreadHeader);

            Content testContent = new Content()
            {
                threadContent = content,
                threadId      = currenthread.ThreadId
            };
            ContentDal cDal = new ContentDal();

            cDal.Contents.Add(testContent);
            cDal.SaveChanges();

            //Act
            controller.addComment(testContent, cur, "TestComment");

            //Assert
            CommentDal comDal = new CommentDal();

            List <Comment> com =
                (from x in comDal.Comments
                 where x.threadId == currenthread.ThreadId
                 select x).ToList();

            Comment ans = com.Find(b => b.commentContent == "TestComment");

            Assert.IsNotNull(ans);

            //CleanUp
            tDal.Threads.Remove(currenthread);
            tDal.SaveChanges();

            cDal.Contents.Remove(testContent);
            cDal.SaveChanges();

            comDal.Comments.Remove(ans);
            comDal.SaveChanges();
        }