예제 #1
0
        public async Task Execute(InputData inputData, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                var countries = await _countriesService.GetAll(inputData.Filter);

                cancellationToken.ThrowIfCancellationRequested();

                var outputDataCountries = countries.Select(country => new OutputDataCountryItem(
                                                               country.Name,
                                                               country.Abbreviation,
                                                               country.Flag,
                                                               country.Currencies.Select(currency => new OutputDataCountryCurrencyItem(currency.Name)).ToArray(),
                                                               country.EconomicGroups.Select(regionalBloc => new OutputDataCountryEconomicBlocItem(regionalBloc.Acronym, regionalBloc.Name)).ToArray()
                                                               )).ToList();

                var outputData = new OutputData(outputDataCountries);

                cancellationToken.ThrowIfCancellationRequested();

                _outputPort.Success(outputData);
            }
            catch (OperationCanceledException)
            {
                _outputPort.Cancelled();
            }
            catch (InvalidOperationException)
            {
                _outputPort.ExternalServiceError();
            }
        }
예제 #2
0
        public async Task Execute(InputData inputData)
        {
            try
            {
                var country = await _countriesService.FindByName(inputData.Name);

                if (country is null)
                {
                    throw new ArgumentOutOfRangeException("Name", inputData.Name, Resources.CountryNameNotFound);
                }

                var outputData = new OutputData(
                    country.Name,
                    country.Abbreviation,
                    country.Flag,
                    country.Population,
                    country.Capital,
                    country.Region,
                    country.Currencies.Select(currency => new OutputDataCurrency(currency.Name)).ToArray(),
                    country.EconomicGroups.Select(economicBloc => new OutputDataEconomicBloc(economicBloc.Acronym, economicBloc.Name)).ToArray(),
                    country.Languages,
                    country.Timezones,
                    country.Borders);

                _outputPort.Success(outputData);
            }
            catch (ArgumentOutOfRangeException outOfRangeEx)
            {
                _outputPort.NotFound(outOfRangeEx.ActualValue);
            }
        }
        public async Task Handle(int input, IOutputPort <TodoDetailsOutputModel> output)
        {
            var todo = await todoGateway.Details(input);

            if (todo == null)
            {
                output.Error($"Todo with id: {input} does not exist in our database!");
            }
            else
            {
                var username    = userService.GetUserName(todo.UserId);
                var outputModel = new TodoDetailsOutputModel(todo.Title, todo.Content, username);
                output.Success(outputModel);
            }
        }
예제 #4
0
        public async Task Handle(int input, IOutputPort <ArticleDetailsOutputModel> output)
        {
            var article = await this.articleGateway.Details(input);

            if (article == null)
            {
                this.logger.LogInformation($"Article {input} could not be found.");
                output.Error();
                return;
            }

            var author = this.userProvider.GetUserName(article.UserId);

            output.Success(new ArticleDetailsOutputModel(
                               article.Id,
                               article.Title,
                               article.Content,
                               article.IsPublic,
                               article.PublishedOn,
                               author));
        }
예제 #5
0
        public async Task Execute(InputData inputData)
        {
            try
            {
                var countries = await _countriesService.GetByRegion(inputData.RegionName);

                var outputDataCountries = countries.Select(country => new OutputDataCountryItem(
                                                               country.Name,
                                                               country.Abbreviation,
                                                               country.Flag
                                                               )).ToList();

                var outputData = new OutputData(outputDataCountries);

                _outputPort.Success(outputData);
            }
            catch (InvalidOperationException)
            {
                _outputPort.ExternalServiceError();
            }
        }
예제 #6
0
        public async Task Execute(InputData inputData)
        {
            try
            {
                var originCountry = await _countriesService.FindByName(inputData.Origin);

                if (originCountry is null)
                {
                    throw new ArgumentOutOfRangeException(Resources.CountryNameNotFound);
                }

                var destinyCountry = await _countriesService.FindByName(inputData.Destiny);

                if (destinyCountry is null)
                {
                    throw new ArgumentOutOfRangeException(Resources.CountryNameNotFound);
                }

                if (!destinyCountry.Region.Equals(originCountry.Region))
                {
                    throw new ArgumentOutOfRangeException(Resources.CountryNameNotFound);
                }

                var countriesInRoute = await _countriesService.GetRoute(originCountry, destinyCountry);

                var outputDataCountries = countriesInRoute.Select(
                    country => new OutputDataRouteCountryItem(
                        country.Name,
                        country.Flag)
                    ).ToList();

                var outputData = new OutputData(outputDataCountries);

                _outputPort.Success(outputData);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                _outputPort.InvalidData(ex.Message);
            }
        }