/// <summary>
        /// Get all the groups that the user is not join in
        /// </summary>
        /// <returns>A list with the groups that the user is not join in</returns>
        /// See <see cref="Areas.GroupManage.Models.GroupInfo"/> to see the response structure
        public List <GroupInfo> getAllGroups()
        {
            User user = TokenUserManager.getUserFromToken(HttpContext, _context);

            if (!user.open)
            {
                return(new List <GroupInfo>());
            }
            bool         isAdmin = AdminPolicy.isAdmin(user, _context);
            List <Group> groups  = !isAdmin?_context.Group.Where(g => g.open).Take(25).ToList()
                                       : _context.Group.Take(25).ToList();

            return(MakeGroupInfoList.make(groups, AdminPolicy.isAdmin(user, _context), _context));
        }
示例#2
0
        /// <summary>
        /// Get a list of groups with a similar name
        /// </summary>
        /// <param name="name">The name of the group to find</param>
        /// <returns>A list of group with a similar name</returns>
        /// See <see cref="Areas.GroupManage.Models.GroupInfo"/> to see the response structure
        public List <GroupInfo> searchGroupByName(string name)
        {
            User user = TokenUserManager.getUserFromToken(HttpContext, _context);

            name = name.ToLower().Trim();

            if (!user.open)
            {
                return(new List <GroupInfo>());
            }

            //The request name is empty
            if (name == null || name.Length == 0)
            {
                return(new List <GroupInfo>());
            }

            bool         isAdmin = AdminPolicy.isAdmin(user, _context);
            List <Group> groupsWithTheSameName = !isAdmin?
                                                 _context.Group.Where(g => g.name.ToLower().Contains(name) && g.open).ToList() :
                                                     _context.Group.Where(g => g.name.ToLower().Contains(name)).ToList();

            return(MakeGroupInfoList.make(groupsWithTheSameName, AdminPolicy.isAdmin(user, _context), _context));
        }