//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")); }
//Action result for submmiting the new post public ActionResult new_thread() { current_thread = new Thread() { Author = ((SuperUser)Session["user"]).Username, Title = Request.Form["t_title"].ToString(), Body = Request.Form["t_body"].ToString(), time = DateTime.Now }; //current_thread.Body = "<pre>" + Request.Form["t_body"].ToString() + "</pre>"; //current_thread.Body.Replace("\r\n", Environment.NewLine); //post comment on sql ThreadDal tdal = new ThreadDal(); tdal.Threads.Add(current_thread); tdal.SaveChanges(); //order the comment list List <Thread> f = tdal.Threads.ToList <Thread>(); f.OrderBy(x => x.time.TimeOfDay).ToList(); f.Reverse(); Thread_list = new ArrayList(f); //set the bag again ViewBag.list = Thread_list; ViewBag.Comments = Comment_list; //resend the view with the model return(View("ThreadPage", current_thread)); }
//Get all thread in json format public ActionResult GetThreadJson() { ThreadDal dal = new ThreadDal(); List <Thread> list = dal.Threads.ToList <Thread>(); return(Json(list, JsonRequestBehavior.AllowGet)); }
//Action result for the threads page public ActionResult Threads() { ThreadDal threads = new ThreadDal(); Thread_list = new ArrayList(threads.Threads.ToList <Thread>()); ViewBag.list = Thread_list; ViewBag.message = getMessage(); return(View()); }
public void TestCreateNewThread() { //Arrange 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 }; //Act controller.CreateNewThread(inst, test_Thread, cur, content); //Assert using (ContentDal cnt = new ContentDal()) { List <Content> cont = (from x in cnt.Contents where x.threadName == test_Thread.ThreadName select x).ToList(); Assert.AreEqual(content, cont[0].threadContent); //Cleanup cnt.Contents.Remove(cont[0]); cnt.SaveChanges(); } //Cleanup Remove testing Thread //Add test thread to DB using (ThreadDal trdDal = new ThreadDal()) { var result = trdDal.Threads.SingleOrDefault(b => b.ThreadName == test_Thread.ThreadName); trdDal.Threads.Remove(result); trdDal.SaveChanges(); } }
public ActionResult unFollow(Int32 i) { ThreadDal tdal = new ThreadDal(); CommentDal cdal = new CommentDal(); FollowDal fdal = new FollowDal(); List <Follow> follows = new List <Follow>(); List <Comment> comments = new List <Comment>(); List <Thread> threads = new List <Thread>(); User ur = new User((User)TempData["urid"]); try { comments = (from x in cdal.Comments where x.commentId == i select x).ToList <Comment>(); int on = comments[0].userId; int tid = comments[0].threadId; int fwr = ur.id; threads = (from x in tdal.Threads where x.ThreadId == tid select x).ToList <Thread>(); follows = (from y in fdal.Follows where y.followOn == @on && y.follower == fwr select y).ToList <Follow>(); fdal.Follows.Remove(follows[0]); fdal.SaveChanges(); } catch { } Thread t = new Thread(threads[0]); return(RedirectToAction("ContentPage", "MainPage", t)); }
//Action result for user or admin panel according to the session public ActionResult userHomePage() { su = Session["user"] as SuperUser; if (message != null) { ViewBag.message = getMessage(); } ThreadDal t_dal = new ThreadDal(); ViewBag.threads = t_dal.Threads.ToList <Thread>(); if (su.getType() == "RICK") { List <User> users = new List <User>(); UserDAL dal = new UserDAL(); users = dal.Users.ToList <User>(); ViewBag.mortys = users; return(View("RickPage")); } return(View("MortyPage")); }
public void TestUnLockThread() { //Arrange var controller = new MainPageControllerTest(); Thread test_Thread = new Thread { ThreadName = testingThreadHeader, SyearId = 1, ThreadType = "[Question]", OwnerId = 1 }; //Add test thread to DB using (ThreadDal trdDal = new ThreadDal()) { trdDal.Threads.Add(test_Thread); trdDal.SaveChanges(); } //Act controller.UnLockThread(test_Thread); //Assert using (ThreadDal trdDal = new ThreadDal()) { List <Thread> testTrd = (from x in trdDal.Threads where x.ThreadName == test_Thread.ThreadName select x).ToList(); Assert.AreEqual(testTrd[0].Locked, false); //Cleanup trdDal.Threads.Remove(testTrd[0]); trdDal.SaveChanges(); } }
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(); }
public ActionResult ViewThreadsActivity() { User cur = getUser(); //cur = (User)TempData["CurrentManager"]; int countComment = 0; ManageConnectionDal mcdal = new ManageConnectionDal(); List <ManageConnection> manageConnections = (from x in mcdal.ManageConnections where x.managerId == cur.id select x).ToList <ManageConnection>(); foreach (ManageConnection mc in manageConnections) { if (mc.institution != -1) { DepartmentDal dp = new DepartmentDal(); List <Department> departments = (from x in dp.Departments where x.InstitutionId == mc.institution select x).ToList <Department>(); foreach (Department dep in departments) { SyearDal yearid = new SyearDal(); List <Syear> syears = (from x in yearid.Syears where x.DepartmentId == dep.DepartmentId select x).ToList <Syear>(); foreach (Syear yearsC in syears) { ThreadDal threadid = new ThreadDal(); List <Thread> threads = (from x in threadid.Threads where x.SyearId == yearsC.SyearId select x).ToList <Thread>(); foreach (Thread th in threads) { CommentDal commentid = new CommentDal(); List <Comment> comments = (from x in commentid.Comments where x.threadId == th.ThreadId select x).ToList <Comment>(); countComment = countComment + comments.Count(); } } } } if (mc.department != -1) { SyearDal yearid = new SyearDal(); List <Syear> syears = (from x in yearid.Syears where x.DepartmentId == mc.department select x).ToList <Syear>(); foreach (Syear yearsC in syears) { ThreadDal threadid = new ThreadDal(); List <Thread> threads = (from x in threadid.Threads where x.SyearId == yearsC.SyearId select x).ToList <Thread>(); foreach (Thread th in threads) { CommentDal commentid = new CommentDal(); List <Comment> comments = (from x in commentid.Comments where x.threadId == th.ThreadId select x).ToList <Comment>(); countComment = countComment + comments.Count(); } } } if (mc.sYear != -1) { ThreadDal threadid = new ThreadDal(); List <Thread> threads = (from x in threadid.Threads where x.SyearId == mc.sYear select x).ToList <Thread>(); foreach (Thread th in threads) { CommentDal commentid = new CommentDal(); List <Comment> comments = (from x in commentid.Comments where x.threadId == th.ThreadId select x).ToList <Comment>(); countComment = countComment + comments.Count(); } } } using (commentCounterDal dal = new commentCounterDal()) { commentCounter newCounter = new commentCounter() { managerId = cur.id, messageCounter = countComment, date = DateTime.Today }; dal.commentCounters.Add(newCounter); dal.SaveChanges(); } commentCounterDal cmpCount = new commentCounterDal(); List <commentCounter> commentCounters = (from x in cmpCount.commentCounters where x.managerId == cur.id select x).ToList <commentCounter>(); ViewBag.counters = commentCounters; return(View("ThreadsActivity", cur)); }