Пример #1
0
        //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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }