public List <DeviceTypeNestedDto> DeviceTypeTree(int?parentId)
        {
            var allDeviceTypes = _deviceTypeRepository.GetAll().Where(x => x.ParentId == parentId).ToList();
            var list           = new List <DeviceTypeNestedDto>();

            foreach (var listType in allDeviceTypes)
            {
                var listDeviceTypes = new DeviceTypeNestedDto();
                listDeviceTypes.Id          = listType.Id;
                listDeviceTypes.Name        = listType.Name;
                listDeviceTypes.ParentId    = listType.ParentId;
                listDeviceTypes.Description = listType.Description;
                listDeviceTypes.Items       = DeviceTypeTree(listType.Id);
                list.Add(listDeviceTypes);
            }
            return(ObjectMapper.Map <List <DeviceTypeNestedDto> >(list));
        }
        //izlistavanje ugnijezdenih tipova
        public List <DeviceTypeNestedDto> GetDeviceTypeNestedDtos(int?parentId)
        {
            var deviceTypes = _repositoryDeviceType.GetAll()
                              .Where(c => c.ParentDeviceTypeId == parentId).ToList();

            var result = new List <DeviceTypeNestedDto>();

            foreach (var deviceType in deviceTypes)
            {
                var currentType = new DeviceTypeNestedDto
                {
                    Id          = deviceType.Id,
                    Name        = deviceType.Name,
                    Description = deviceType.Description,
                    Parentid    = deviceType.ParentDeviceTypeId,
                    Children    = GetDeviceTypeNestedDtos(deviceType.Id)
                };

                result.Add(currentType);
            }

            return(result);
        }
Пример #3
0
        public List <DeviceTypeNestedDto> GetDeviceTypes(int?parentId)
        {
            var baseDeviceTypes = _deviceTypeRepository.GetAll()
                                  .Where(x => x.ParentId == parentId).ToList();

            var result = new List <DeviceTypeNestedDto>();

            foreach (var deviceType in baseDeviceTypes)
            {
                var currentType = new DeviceTypeNestedDto
                {
                    Id          = deviceType.Id,
                    Name        = deviceType.Name,
                    Description = deviceType.Description,
                    ParentId    = deviceType.ParentId,
                    Items       = GetDeviceTypes(deviceType.Id)
                };

                result.Add(currentType);
            }

            return(result);
        }