// GET: Group
        public ActionResult Index(int id = 1)
        {
            if (!Permission.LoginedNeed(Request, Response, Session))
            {
                return(null);
            }

            IOrderedQueryable <Group> groups = null;

            if (groupsCache != null)
            {
                groups = groupsCache;
            }
            else
            {
                groups      = GroupView.GetAllGroups();
                groupsCache = groups;
            }

            int totalPageNumber = pager.GetPageNumber(groups);

            if (id > totalPageNumber || id < 1)
            {
                id = 1;
            }
            ViewBag.totalPageNumber = totalPageNumber;
            ViewBag.groups          = pager.GetPage(groups, id);
            ViewBag.page            = id;
            ViewBag.user            = (User)Session["user"];

            return(View());
        }
        public JsonResult Dismiss()
        {
            if (!Permission.LoginedNeed(Request, Response, Session))
            {
                return(Json(false));
            }

            User        user       = (User)Session["user"];
            int         gid        = Convert.ToInt32(Request["gid"]);
            GroupMember memberInfo = GroupView.GetGroupMember(user.uid, gid);

            if (memberInfo == null || memberInfo.rank != (int)MemberRank.CREATOR)
            {
                return(Json(false));
            }

            groupsCache = GroupView.GetAllGroups();
            return(Json(GroupView.DismissGroup(gid)));
        }
Exemple #3
0
        public ActionResult New()
        {
            if (!Permission.PremissionNeed(Request, Response, Session, UserRank.TEACHER))
            {
                return(null);
            }

            List <Subject> subjects = SubjectView.GetAllSubject().ToList();

            if (subjects == null)
            {
                Permission.BackToPrevPageOrIndex(Request, Response);
                return(null);
            }

            ViewBag.subjects = subjects;
            ViewBag.groups   = GroupView.GetAllGroups().ToList();

            return(View());
        }
        public JsonResult SubmitCreation()
        {
            if (!Permission.PremissionNeed(Request, Response, Session, UserRank.TEACHER))
            {
                return(Json(0));
            }

            string groupName = Request["groupname"];
            bool   allowJoin = Convert.ToBoolean(Request["allowjoin"]);
            bool   allowquit = Convert.ToBoolean(Request["allowquit"]);
            User   user      = (User)Session["user"];

            Group group = new Group
            {
                group_name = groupName,
                owner_uid  = user.uid,
                number     = 0,
                allow_join = allowJoin,
                allow_quit = allowquit
            };

            if (!GroupView.NewGroup(group))
            {
                return(Json(0));
            }

            groupsCache = GroupView.GetAllGroups();

            GroupMember member = new GroupMember
            {
                gid  = group.gid,
                uid  = user.uid,
                rank = (int)MemberRank.CREATOR
            };

            GroupView.AddMember(group.gid, member);

            return(Json(group.gid));
        }