public void TestBlockUser() { //Arrange var controller = new ManagerControllerTests(); //Add Manager User UserDal usrDal = new UserDal(); User managerUser = new User { UserName = "******", Password = "******", rank = 1, Email = "*****@*****.**", EmailConfirmed = true, active = true }; usrDal.Users.Add(managerUser); usrDal.SaveChanges(); managerUser = usrDal.Users.SingleOrDefault(b => b.UserName == "TestManagerUser"); //Add to managing connection ManageConnectionDal magDal = new ManageConnectionDal(); ManageConnection magObj = new ManageConnection { managerId = managerUser.id, institution = 1, sYear = -1, department = -1 }; magDal.ManageConnections.Add(magObj); magDal.SaveChanges(); //Add User to be blocked User blockedUser = new User { UserName = "******", Password = "******", rank = 0, Email = "*****@*****.**", active = true, EmailConfirmed = true }; usrDal.Users.Add(blockedUser); usrDal.SaveChanges(); //Act controller.BlockUser(managerUser, "NewUser", DateTime.Now, 1, -1, -1); //Assert BlockedDal blkdal = new BlockedDal(); List <Blocked> blk = (from x in blkdal.Blockeds where x.UserName == blockedUser.UserName select x).ToList(); Assert.AreEqual(blk[0].UserName.Replace(" ", ""), blockedUser.UserName.Replace(" ", "")); //Clean up usrDal.Users.Remove(managerUser); usrDal.Users.Remove(blockedUser); usrDal.SaveChanges(); magDal.ManageConnections.Remove(magObj); magDal.SaveChanges(); blkdal.Blockeds.Remove(blk[0]); blkdal.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)); }
public ActionResult saveMsg(User usr) { string rec; string subj; string msgC; try { rec = Request.Form["to"]; subj = Request.Form["subject"]; msgC = Request.Form["msgContent"]; } catch { return(View("Error", new User(usr))); } int inst, dep, yr; try { inst = Int32.Parse(Request.Form["inst"]); } catch { inst = -1; } try { dep = Int32.Parse(Request.Form["dep"]); } catch { dep = -1; } try { yr = Int32.Parse(Request.Form["yr"]); } catch { yr = -1; } if (yr + dep + inst > -3) { if (usr.rank == 0) { if (yr != -1) { saveBrodMsg(new User(usr), 0, yr, rec, subj, msgC); } else if (dep != -1) { saveBrodMsg(new User(usr), 1, dep, rec, subj, msgC); } else if (inst != -1) { saveBrodMsg(new User(usr), 2, inst, rec, subj, msgC); } return(RedirectToAction("InboxPage", new User(usr))); } if (usr.rank == 1) { List <ManageConnection> manageConnections = new List <ManageConnection>(); if (yr != -1) { try { ManageConnectionDal mcdal = new ManageConnectionDal(); manageConnections = (from x in mcdal.ManageConnections where x.managerId == usr.id && x.sYear == yr select x).ToList <ManageConnection>(); } catch { } if (manageConnections.Any()) { saveBrodMsg(new User(usr), 0, yr, rec, subj, msgC); } } else if (dep != -1) { try { ManageConnectionDal mcdal = new ManageConnectionDal(); manageConnections = (from x in mcdal.ManageConnections where x.managerId == usr.id && x.department == dep select x).ToList <ManageConnection>(); } catch { } if (manageConnections.Any()) { saveBrodMsg(new User(usr), 1, dep, rec, subj, msgC); } } else if (inst != -1) { try { ManageConnectionDal mcdal = new ManageConnectionDal(); manageConnections = (from x in mcdal.ManageConnections where x.managerId == usr.id && x.institution == inst select x).ToList <ManageConnection>(); } catch { } if (manageConnections.Any()) { saveBrodMsg(new User(usr), 2, inst, rec, subj, msgC); } } return(RedirectToAction("InboxPage", new User(usr))); } } MessageDal mdal = new MessageDal(); Message ms = new Message() { date = DateTime.Now, senderName = usr.UserName, reciverName = rec, mag = msgC, subject = subj }; List <User> user = new List <User>(); try { UserDal dal = new UserDal(); user = (from x in dal.Users where x.UserName == usr.UserName select x).ToList <User>(); } catch { } if (user.Any()) { mdal.Messages.Add(ms); mdal.SaveChanges(); } return(RedirectToAction("InboxPage", new User(usr))); }
//Modified for testing public ActionResult BlockUser(User cur, string blockName, DateTime date, int InstId, int DepId, int YearId) { //User cur = new User(); //cur = (User)TempData["CurrentManager"]; //string UserName = Request.Form["username"]; string UserName = blockName; //int InstId; //int DepId; //int YearId; //try //{ // InstId = Int32.Parse(Request.Form["Institution"]); //} //catch //{ // InstId = -1; //} //try //{ // DepId = Int32.Parse(Request.Form["Department"]); //} //catch //{ // DepId = -1; //} //try //{ // YearId = Int32.Parse(Request.Form["Year"]); //} //catch //{ // YearId = -1; //} 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 (InstId != -1) { if (mc.institution == InstId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } } if (DepId != -1) { if (mc.department == DepId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } else { DepartmentDal dp = new DepartmentDal(); List <Department> departments = (from x in dp.Departments where x.DepartmentId == DepId select x).ToList <Department>(); if (mc.institution == departments[0].InstitutionId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } } } if (YearId != -1) { if (mc.sYear == YearId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } else { SyearDal yearid = new SyearDal(); List <Syear> syears = (from x in yearid.Syears where x.SyearId == YearId select x).ToList <Syear>(); DepartmentDal dp = new DepartmentDal(); List <Department> departments = (from x in dp.Departments where x.DepartmentId == syears[0].DepartmentId select x).ToList <Department>(); if (mc.institution == departments[0].InstitutionId || mc.department == syears[0].DepartmentId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } } } } return(View("Failed", cur)); }
public ActionResult BlockUser() { User cur = new User(); cur = (User)TempData["CurrentManager"]; string UserName = Request.Form["username"]; int InstId; int DepId; int YearId; DateTime date = DateTime.Parse(Request.Form["date"]); try { InstId = Int32.Parse(Request.Form["Institution"]); } catch { InstId = -1; } try { DepId = Int32.Parse(Request.Form["Department"]); } catch { DepId = -1; } try { YearId = Int32.Parse(Request.Form["Year"]); } catch { YearId = -1; } List <ManageConnection> manageConnections = new List <ManageConnection>(); try { ManageConnectionDal mcdal = new ManageConnectionDal(); manageConnections = (from x in mcdal.ManageConnections where x.managerId == cur.id select x).ToList <ManageConnection>(); } catch { } foreach (ManageConnection mc in manageConnections) { if (InstId != -1) { if (mc.institution == InstId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } } if (DepId != -1) { if (mc.department == DepId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } else { List <Department> departments = new List <Department>(); try { DepartmentDal dp = new DepartmentDal(); departments = (from x in dp.Departments where x.DepartmentId == DepId select x).ToList <Department>(); } catch { } if (mc.institution == departments[0].InstitutionId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } } } if (YearId != -1) { if (mc.sYear == YearId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } else { List <Syear> syears = new List <Syear>(); List <Department> departments = new List <Department>(); SyearDal yearid = new SyearDal(); DepartmentDal dp = new DepartmentDal(); try { syears = (from x in yearid.Syears where x.SyearId == YearId select x).ToList <Syear>(); departments = (from x in dp.Departments where x.DepartmentId == syears[0].DepartmentId select x).ToList <Department>(); } catch { } if (mc.institution == departments[0].InstitutionId || mc.department == syears[0].DepartmentId) { BlockFromDB(UserName, date, InstId, DepId, YearId); return(View("Block", cur)); } } } } return(View("Failed", cur)); }