Пример #1
0
        public async Task <RackDto> GetAvailablePowerPorts(Guid id)
        {
            var rack = await _rackRepository.GetRackAsync(id);

            // include only ports without a connection
            rack.Pdus.ForEach(pdu => pdu.Ports = pdu.Ports.Where(port => port.PowerConnection is null)
                                                 .ToList());

            return(_mapper.Map <RackDto>(rack));
        }
Пример #2
0
        public async Task <AssetDto> FillFieldsInAssetApiForChangePlans(AssetDto assetDto)
        {
            var original = _mapper.Map <AssetDto>(await _assetRepository.GetAssetAsync(assetDto.Id));

            if (original != null)
            {
                assetDto.Blades = original.Blades;
            }
            else
            {
                assetDto.Blades = new List <AssetDto>();
            }
            assetDto.Model = _mapper.Map <ModelDto>(await _modelRepository.GetModelAsync(assetDto.ModelId));
            assetDto.Rack  = _mapper.Map <RackDto>(await _rackRepository.GetRackAsync(assetDto.RackId));
            if (assetDto.OwnerId != null || assetDto.OwnerId != Guid.Empty)
            {
                assetDto.Owner = _mapper.Map <UserDto>(await _userRepository.GetUserAsync(assetDto.OwnerId ?? Guid.Empty));
            }
            foreach (AssetNetworkPortDto assetNetworkPortDto in assetDto.NetworkPorts)
            {
                var networkPortModelId = assetNetworkPortDto.ModelNetworkPortId;
                assetNetworkPortDto.ModelNetworkPort = assetDto.Model.NetworkPorts.Find(x => x.Id == networkPortModelId);
                if (assetNetworkPortDto.ConnectedPortId != null)
                {
                    var connectedPort = await _assetRepository.GetNetworkPortAsync(assetNetworkPortDto.ConnectedPortId ?? Guid.Empty);

                    assetNetworkPortDto.ConnectedPort = _mapper.Map <AssetNetworkPortDto>(connectedPort);
                }
            }
            int count = 1;

            foreach (AssetPowerPortDto assetPowerPortDto in assetDto.PowerPorts)
            {
                assetPowerPortDto.Number = count;
                if (assetPowerPortDto.PduPortId != null)
                {
                    var connectedPort = await _assetRepository.GetPowerPortAsync(assetPowerPortDto.PduPortId ?? Guid.Empty);

                    assetPowerPortDto.PduPort = _mapper.Map <PduPortDto>(connectedPort);
                }
                count++;
            }
            return(assetDto);
        }