Example #1
0
        public async Task <Guid> CreateNetworkAsync(NewNetwork newNetwork)
        {
            NetworkModel network = NetworkModel.CreateNew(
                newNetwork.Name,
                newNetwork.Description,
                newNetwork.OwnerId);

            await _networkRepository.CreateNetworkAsync(network);

            _versionsStorage.Init(network.Id);

            return(network.Id);
        }
        public async Task <string> Handle(CreateNetworkRequest request, CancellationToken cancellationToken)
        {
            var parameters    = _mapper.Map <NetworksCreateParameters>(request.NetworkDto);
            var networkEntity = await _networkRepository.CreateNetworkAsync(parameters);

            return(networkEntity switch
            {
                null when request.NetworkDto.Subnet != null &&
                string.IsNullOrWhiteSpace(request.NetworkDto.Subnet) => throw new StatusException(
                    StatusCodes.Status400BadRequest,
                    $"An other network does overlap with the subnet '{request.NetworkDto.Subnet}'."),
                null => throw new StatusException(StatusCodes.Status500InternalServerError,
                                                  "Could not create the requested network."),
                _ => networkEntity.ID
            });