public async Task <IActionResult> GetHolidaysByMonth([FromRoute] Guid token, string countryIsoCode, int year, int month) { 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 GetHolidaysByMonthRequest() { CountryIsoCode = countryIsoCode, Year = year, Month = month }; commandResult = await _queryHolidaysByMonth.GetHolidaysByMonthAsync(request); } commandResponse = FormatResponse(commandResult); } watch.Stop(); commandResponse.ElapsedTime = watch.ElapsedMilliseconds; return(StatusCode(commandResponse.StatusCode, commandResponse)); }
public async Task <CommandResult> GetHolidaysByMonthAsync(GetHolidaysByMonthRequest request) { _commandName = request.GetType().Name; CommandResult commandResult; Stopwatch watch = Stopwatch.StartNew(); try { if (!await CanGetHolidaysByMonthAsync(request)) { commandResult = CommandResult.BadRequest("Não foi possível realizar a consulta."); } else { var holidays = await GetHolidaysByMonthAsync(request.CountryIsoCode, request.Year, request.Month); 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}/{request.Month}."); } } } catch (Exception) { commandResult = CommandResult.InternalServerError($"Ocorreu um erro na busca."); } watch.Stop(); commandResult.ElapsedTime = watch.ElapsedMilliseconds; return(commandResult); }
private async Task <bool> CanGetHolidaysByMonthAsync(GetHolidaysByMonthRequest request) { return(InstanceNotNull(request) && (await IsValidRequestAsync(_getHolidaysByMonthRequestValidator, request))); }