コード例 #1
0
ファイル: SearchController.cs プロジェクト: bmtuaf/Challenge
        public async Task <IActionResult> SearchUserHistoricalReservationsAsync(SearchUserReservation search)
        {
            var result = await searchService.SearchUserHistoricalReservationsAsync(search);

            if (result.IsSuccess)
            {
                return(Ok(result.SearchResults));
            }
            return(NotFound());
        }
コード例 #2
0
        public async Task <(bool IsSuccess, IEnumerable <Reservation> Reservations, string ErrorMessage)> GetUsersReservationsAsync(SearchUserReservation search)
        {
            try
            {
                //var authenticateInfo = await AuthenticationHttpContextExtensions.GetTokenAsync(,"Bearer");
                //string accessToken = authenticateInfo..Properties.Items[".Token.access_token"];
                var client   = httpClientFactory.CreateClient("ReservationsService");
                var response = await client.GetAsync($"api/reservations/user/active/{search.CPF}");

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsByteArrayAsync();

                    var options = new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    };
                    var result = JsonSerializer.Deserialize <IEnumerable <Reservation> >(content, options);
                    return(true, result, null);
                }
                return(false, null, response.ReasonPhrase);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
                return(false, null, ex.Message);
            }
        }
コード例 #3
0
        public async Task <(bool IsSuccess, IEnumerable <Reservation> Reservations, string ErrorMessage)> GetUsersHistoricalReservationsAsync(SearchUserReservation search)
        {
            try
            {
                var client   = httpClientFactory.CreateClient("ReservationsService");
                var response = await client.GetAsync($"api/reservations/user/historical/{search.CPF}");

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsByteArrayAsync();

                    var options = new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    };
                    var result = JsonSerializer.Deserialize <IEnumerable <Reservation> >(content, options);
                    return(true, result, null);
                }
                return(false, null, response.ReasonPhrase);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
                return(false, null, ex.Message);
            }
        }
コード例 #4
0
        public async Task <(bool IsSuccess, dynamic SearchResults)> SearchUserHistoricalReservationsAsync(SearchUserReservation search)
        {
            var reservationsResult = await reservationsService.GetUsersHistoricalReservationsAsync(search);

            if (reservationsResult.IsSuccess)
            {
                var result = new
                {
                    Reservations = reservationsResult.Reservations
                };
                return(true, result);
            }
            return(false, null);
        }