Example #1
0
        public async Task <IActionResult> GetHolidaysByCountry([FromRoute] Guid token, string countryIsoCode, int year)
        {
            CommandResponse commandResponse;
            Stopwatch       watch = Stopwatch.StartNew();

            if (!ModelState.IsValid)
            {
                commandResponse = FormatResponse(ModelState);
            }
            else
            {
                CommandResult commandResult;

                if (token != _bigaiId)
                {
                    commandResult = CommandResult.Unauthorized("Authorization token is not valid.");
                }
                else
                {
                    var request = new GetHolidaysByCountryRequest()
                    {
                        CountryIsoCode = countryIsoCode,
                        Year           = year
                    };
                    commandResult = await _queryHolidaysByCountry.GetHolidaysByCountryAsync(request);
                }
                commandResponse = FormatResponse(commandResult);
            }

            watch.Stop();
            commandResponse.ElapsedTime = watch.ElapsedMilliseconds;

            return(StatusCode(commandResponse.StatusCode, commandResponse));
        }
Example #2
0
        public async Task <CommandResult> GetHolidaysByCountryAsync(GetHolidaysByCountryRequest request)
        {
            _commandName = request.GetType().Name;
            CommandResult commandResult;
            Stopwatch     watch = Stopwatch.StartNew();

            try
            {
                if (!await CanGetHolidaysByCountryAsync(request))
                {
                    commandResult = CommandResult.BadRequest("Não foi possível realizar a consulta.");
                }
                else
                {
                    var holidays = await GetHolidaysByCountryAsync(request.CountryIsoCode, request.Year);

                    if (holidays != null && holidays.Count() > 0)
                    {
                        commandResult      = CommandResult.Ok($"{holidays.Count()} feriados encontrados.");
                        commandResult.Data = holidays.ToResponse();
                    }
                    else
                    {
                        commandResult = CommandResult.BadRequest($"Não existe feriado cadastrado para {request.CountryIsoCode} em {request.Year}.");
                    }
                }
            }
            catch (Exception)
            {
                commandResult = CommandResult.InternalServerError($"Ocorreu um erro na busca.");
            }

            watch.Stop();
            commandResult.ElapsedTime = watch.ElapsedMilliseconds;

            return(commandResult);
        }
Example #3
0
 private async Task <bool> CanGetHolidaysByCountryAsync(GetHolidaysByCountryRequest request)
 {
     return(InstanceNotNull(request) && (await IsValidRequestAsync(_getHolidaysByCountryRequestValidator, request)));
 }