public IEnumerable <DeviceTypePropertiesNestedDto> DeviceTypeTreeWithProperties(int?deviceId)
        {
            var allDeviceTypes = _deviceTypeRepository.GetAll().Include(y => y.DeviceTypeProperty).Where(x => x.Id == deviceId).First();
            var list           = new List <DeviceTypePropertiesNestedDto>();

            var device = new DeviceTypePropertiesNestedDto()
            {
                Id          = allDeviceTypes.Id,
                Name        = allDeviceTypes.Name,
                Description = allDeviceTypes.Description,
                ParentId    = allDeviceTypes.ParentId,
                Properties  = ObjectMapper.Map <List <DeviceTypePropertyDto> >(allDeviceTypes.DeviceTypeProperty)
            };

            if (_deviceTypeRepository.GetAll().Count() == 1)
            {
                list.Add(device);
                return(list);
            }
            if (allDeviceTypes.ParentId == null)
            {
                list.Add(device);
                return(list);
            }
            list.Add(device);

            return(list.Concat(DeviceTypeTreeWithProperties(allDeviceTypes.ParentId)).OrderBy(x => x.Id));
        }
예제 #2
0
        /// <summary>
        ///     Return all DeviceTypes include Properties
        /// </summary>
        /// <param name="deviceTypeId"></param>
        /// <returns></returns>
        public IEnumerable <DeviceTypePropertiesNestedDto> GetDeviceTypesWithProperties(int?deviceTypeId)
        {
            var allDeviceTypes = _deviceTypeRepository.GetAll().Include(x => x.DeviceTypeProperties)
                                 .First(x => x.Id == deviceTypeId);

            var result = new List <DeviceTypePropertiesNestedDto>();

            var currentType = new DeviceTypePropertiesNestedDto
            {
                Id          = allDeviceTypes.Id,
                Name        = allDeviceTypes.Name,
                Description = allDeviceTypes.Description,
                ParentId    = allDeviceTypes.ParentId,
                Properties  = ObjectMapper.Map <List <DeviceTypePropertyDto> >(allDeviceTypes.DeviceTypeProperties)
            };

            if (allDeviceTypes.ParentId == null)
            {
                result.Add(currentType);
                return(result);
            }

            result.Add(currentType);


            return(result.Concat(GetDeviceTypesWithProperties(allDeviceTypes.ParentId)).OrderBy(x => x.Id));
        }