コード例 #1
0
        /// <summary>
        /// Get available user groups.
        /// </summary>
        public GXUserGroupResponse Post(GXUserGroupsRequest request)
        {
            lock (Db)
            {
                List <GXAmiUserGroup> list;
                if (request.UserGroupId != 0)
                {
                    list = new List <GXAmiUserGroup>();
#if !SS4
                    list.Add(Db.GetById <GXAmiUserGroup>(request.UserGroupId));
#else
                    list.Add(Db.SingleById <GXAmiUserGroup>(request.UserGroupId));
#endif
                }
                //Returns the user group(s) to which the device belongs to.
                else if (request.DeviceId != 0)
                {
                    throw new NotImplementedException();
                }
                //Returns the user group(s) to which the device group belongs to.
                else if (request.DeviceGroupId != 0)
                {
                    string query = string.Format("SELECT DISTINCT {0}.* FROM {0} INNER JOIN {1} ON {0}.ID = {1}.UserGroupID WHERE DeviceGroupID={2}",
                                                 GuruxAMI.Server.AppHost.GetTableName <GXAmiUserGroup>(Db),
                                                 GuruxAMI.Server.AppHost.GetTableName <GXAmiUserGroupDeviceGroup>(Db),
                                                 request.DeviceGroupId);
                    list = Db.Select <GXAmiUserGroup>(query);
                }
                else
                {
                    list = GetUserGroups(request.UserId, request.Removed);
                }
                //Remove excluded user groups.
                if (request.Excluded != null && request.Excluded.Length != 0)
                {
                    List <long> ids = new List <long>(request.Excluded);
                    var         excludeUserGroups = from c in list where !ids.Contains(c.Id) select c;
                    list = excludeUserGroups.ToList();
                }
                //Get user groups by range.
                if (request.Index != 0 || request.Count != 0)
                {
                    if (request.Count == 0 || request.Index + request.Count > list.Count)
                    {
                        request.Count = list.Count - request.Index;
                    }
                    list.RemoveRange(0, request.Index);
                    var limitUserGroups = list.Take(request.Count);
                    list = limitUserGroups.ToList();
                }
                return(new GXUserGroupResponse(list.ToArray()));
            }
        }
コード例 #2
0
        /// <summary>
        /// Get available user groups.
        /// </summary>
		public GXUserGroupResponse Post(GXUserGroupsRequest request)
		{
            lock (Db)
            {
                List<GXAmiUserGroup> list;
                if (request.UserGroupId != 0)
                {
                    list = new List<GXAmiUserGroup>();
#if !SS4
                    list.Add(Db.GetById<GXAmiUserGroup>(request.UserGroupId));
#else
                    list.Add(Db.SingleById<GXAmiUserGroup>(request.UserGroupId));                    
#endif                    
                }
                //Returns the user group(s) to which the device belongs to.
                else if (request.DeviceId != 0)
                {
                    throw new NotImplementedException();
                }
                //Returns the user group(s) to which the device group belongs to.
                else if (request.DeviceGroupId != 0)
                {
                    string query = string.Format("SELECT DISTINCT {0}.* FROM {0} INNER JOIN {1} ON {0}.ID = {1}.UserGroupID WHERE DeviceGroupID={2}",
                        GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroup>(Db),
                        GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupDeviceGroup>(Db),
                        request.DeviceGroupId);
                    list = Db.Select<GXAmiUserGroup>(query);
                }
                else
                {
                    list = GetUserGroups(request.UserId, request.Removed);
                }
                //Remove excluded user groups.
                if (request.Excluded != null && request.Excluded.Length != 0)
                {
                    List<long> ids = new List<long>(request.Excluded);
                    var excludeUserGroups = from c in list where !ids.Contains(c.Id) select c;
                    list = excludeUserGroups.ToList();
                }
                //Get user groups by range.
                if (request.Index != 0 || request.Count != 0)
                {
                    if (request.Count == 0 || request.Index + request.Count > list.Count)
                    {
                        request.Count = list.Count - request.Index;
                    }
                    list.RemoveRange(0, request.Index);
                    var limitUserGroups = list.Take(request.Count);
                    list = limitUserGroups.ToList();
                }
                return new GXUserGroupResponse(list.ToArray());
            }
		}