private async Task <Result <Unit, ProblemDetails> > Post(string requestUri, HttpContent content, string languageCode = LocalizationHelper.DefaultLanguageCode, CancellationToken cancellationToken = default) { try { _httpClient.DefaultRequestHeaders.Add("Accept-Language", languageCode); using var response = await _httpClient.PostAsync(requestUri, content, cancellationToken); if (response.IsSuccessStatusCode) { return(Result.Success <Unit, ProblemDetails>(Unit.Instance)); } return(Result.Failure <Unit, ProblemDetails>(await GetProblemDetails(response, cancellationToken))); } catch (TaskCanceledException ex) when(!ex.CancellationToken.IsCancellationRequested) { _logger.LogMapperManagementClientRequestTimeout(ex); return(ProblemDetailsBuilder.Build("Request failure")); } catch (Exception ex) { _logger.LogMapperManagementClientException(ex); return(ProblemDetailsBuilder.Build(ex.Message)); } }
public async Task <Result <TResponse, ProblemDetails> > Send <TResponse>(Func <HttpRequestMessage> requestFactory, string languageCode, CancellationToken cancellationToken) { try { using var response = await ExecuteWithRetryOnUnauthorized(requestFactory, languageCode, cancellationToken); await using var stream = await response.Content.ReadAsStreamAsync(); using var streamReader = new StreamReader(stream); using var jsonTextReader = new JsonTextReader(streamReader); if (!response.IsSuccessStatusCode) { var error = _serializer.Deserialize <ProblemDetails>(jsonTextReader) ?? ProblemDetailsBuilder.Build(response.ReasonPhrase, response.StatusCode); return(Result.Failure <TResponse, ProblemDetails>(error)); } return(_serializer.Deserialize <TResponse>(jsonTextReader)); } catch (Exception ex) { ex.Data.Add("requested url", requestFactory().RequestUri); _logger.LogConnectorClientException(ex); return(ProblemDetailsBuilder.Fail <TResponse>(ex.Message)); } }
private async Task <Result <TResponse, ProblemDetails> > Send <TResponse>(HttpRequestMessage requestMessage, string languageCode = LocalizationHelper.DefaultLanguageCode, CancellationToken cancellationToken = default) { try { _httpClient.DefaultRequestHeaders.Add("Accept-Language", languageCode); using var response = await _httpClient.SendAsync(requestMessage, cancellationToken); if (response.IsSuccessStatusCode) { return((await response.Content.ReadFromJsonAsync <TResponse>(JsonSerializerOptions, cancellationToken)) !); } return(Result.Failure <TResponse, ProblemDetails>(await GetProblemDetails(response, cancellationToken))); } catch (TaskCanceledException ex) when(!ex.CancellationToken.IsCancellationRequested) { _logger.LogMapperManagementClientRequestTimeout(ex); return(ProblemDetailsBuilder.Build("Request failure")); } catch (Exception ex) { _logger.LogMapperManagementClientException(ex); return(ProblemDetailsBuilder.Build(ex.Message)); } }
public async Task <IActionResult> RegisterAdministrator([FromBody] string invitationCode) { var identity = _tokenInfoAccessor.GetIdentity(); if (string.IsNullOrWhiteSpace(identity)) { return(BadRequest(ProblemDetailsBuilder.Build("Could not get user's identity"))); } var email = await _identityUserInfoService.GetUserEmail(); if (string.IsNullOrWhiteSpace(email)) { return(BadRequest(ProblemDetailsBuilder.Build("E-mail claim is required"))); } var(_, isFailure, error) = await _adminInvitationAcceptService.Accept(invitationCode, identity, email); if (isFailure) { return(BadRequest(ProblemDetailsBuilder.Build(error))); } return(NoContent()); }
public async Task <IActionResult> AcceptChildAgencyInvite([FromBody] RegisterInvitedAgencyRequest request) { var identity = _tokenInfoAccessor.GetIdentity(); if (string.IsNullOrWhiteSpace(identity)) { return(BadRequest(ProblemDetailsBuilder.Build("User sub claim is required"))); } var email = await _identityUserInfoService.GetUserEmail(); if (string.IsNullOrWhiteSpace(email)) { return(BadRequest(ProblemDetailsBuilder.Build("E-mail claim is required"))); } var(_, isFailure, error) = await _agentInvitationAcceptService.Accept( request.InvitationCode, request.ToUserInvitationData(), identity, email); if (isFailure) { return(BadRequest(ProblemDetailsBuilder.Build(error))); } return(NoContent()); }
public async Task <IActionResult> RegisterAgentWithAgency([FromBody] RegisterAgentWithAgencyRequest request) { var externalIdentity = _tokenInfoAccessor.GetIdentity(); if (string.IsNullOrWhiteSpace(externalIdentity)) { return(BadRequest(ProblemDetailsBuilder.Build("User sub claim is required"))); } var email = await _identityUserInfoService.GetUserEmail(); if (string.IsNullOrWhiteSpace(email)) { return(BadRequest(ProblemDetailsBuilder.Build("E-mail claim is required"))); } var registerResult = await _agentRegistrationService.RegisterWithAgency(request.Agent, request.Agency, externalIdentity, email); if (registerResult.IsFailure) { return(BadRequest(ProblemDetailsBuilder.Build(registerResult.Error))); } return(NoContent()); }
public async Task <IActionResult> EditAgency([FromRoute] int agencyId, [FromBody] ManagementEditAgencyRequest request) { var localityId = request.LocalityHtId; if (string.IsNullOrWhiteSpace(localityId)) { return(BadRequest(ProblemDetailsBuilder.Build("Locality id is required"))); } var(_, isLocalityFailure, localityInfo, _) = await _localityInfoService.GetLocalityInfo(request.LocalityHtId); if (isLocalityFailure) { return(BadRequest(ProblemDetailsBuilder.Build("Locality doesn't exist"))); } var(_, isFailure, agency, error) = await _agencyManagementService.Edit(agencyId, request, localityInfo, LanguageCode); if (isFailure) { return(BadRequest(ProblemDetailsBuilder.Build(error))); } return(Ok(agency)); }
public async Task<IActionResult> Book([FromBody] EdoContracts.Accommodations.BookingRequest bookingRequest) { var (_, isFailure, bookingDetails, error) = await _bookingService.Book(bookingRequest, LanguageCode); if (isFailure) return BadRequest(ProblemDetailsBuilder.Build(error)); return Ok(bookingDetails); }
public async Task <IActionResult> ConfirmCreditCartPayment(int bookingId) { var(isSuccess, _, error) = await _creditCardPaymentConfirmationService.Confirm(bookingId); return(isSuccess ? NoContent() : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> SetBalanceNotificationSettings(int agencyAccountId, [FromBody] BalanceNotificationSettingInfo info) { var(isSuccess, _, error) = await _balanceNotificationsManagementService.Set(agencyAccountId, info.Thresholds); return(isSuccess ? NoContent() : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> DeclineVerification(int agencyId, [FromBody] AgencyDeclinedVerificationRequest request) { var(isSuccess, _, error) = await _agencyVerificationService.DeclineVerification(agencyId, request.Reason); return(isSuccess ? (IActionResult)NoContent() : BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <ActionResult <Accommodation> > GetAccommodation(string accommodationId) { var(isSuccess, _, accommodation, error) = await _accommodationService.GetAccommodationById(accommodationId, "en"); return(isSuccess ? accommodation : BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <ActionResult <List <Accommodation> > > GetAccommodationsList(DateTimeOffset?modified, [Range(1, 500)] int top = 100, int skip = 0) { var(isSuccess, _, accommodations, error) = await _accommodationService.GetAccommodationList(modified, top, skip, "en"); return(isSuccess ? accommodations : BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> TransferToChildAgency(int payerAccountId, int recipientAccountId, [FromBody] MoneyAmount amount) { var(isSuccess, _, error) = await _accountPaymentService.TransferToChildAgency(payerAccountId, recipientAccountId, amount, await _agentContextService.GetAgent()); return(isSuccess ? NoContent() : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> PayViaNGenius([Required] string code, [FromBody] NGeniusPayByLinkRequest request) { var(isSuccess, _, paymentResponse, error) = await _paymentLinksProcessingService.Pay(code, request, ClientIp, LanguageCode); return(isSuccess ? Ok(paymentResponse) : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> VerifyFullAccess(int agencyId, [FromBody] AgencyFullAccessVerificationRequest request) { var(isSuccess, _, error) = await _agencyVerificationService.VerifyAsFullyAccessed(agencyId, request.ContractKind, request.Reason); return(isSuccess ? (IActionResult)NoContent() : BadRequest(ProblemDetailsBuilder.Build(error))); }
protected IActionResult OkOrBadRequest<T>(Result<T> model) { var (_, isFailure, response, error) = model; if (isFailure) return BadRequest(ProblemDetailsBuilder.Build(error)); return Ok(response); }
public async Task <IActionResult> Verify(int counterpartyId, [FromBody] CounterpartyVerificationRequest request) { var(isSuccess, _, error) = await _counterpartyManagementService.Verify(counterpartyId, request.State, request.Reason); return(isSuccess ? (IActionResult)NoContent() : BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task<IActionResult> Cancel(string referenceCode) { var (_, isFailure, error) = await _bookingService.Cancel(referenceCode); if (isFailure) return BadRequest(ProblemDetailsBuilder.Build(error)); return NoContent(); }
public async Task <IActionResult> GetPaymentData([Required] string code) { var(isSuccess, _, linkData, error) = await _paymentLinkService.Get(code); return(isSuccess ? Ok(linkData) : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> SendLink([FromBody] PaymentLinkCreationRequest creationRequest) { var(isSuccess, _, error) = await _paymentLinkService.Send(creationRequest); return(isSuccess ? NoContent() : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> GenerateUrl([FromBody] PaymentLinkCreationRequest creationRequest) { var(isSuccess, _, uri, error) = await _paymentLinkService.GenerateUri(creationRequest); return(isSuccess ? Ok(uri) : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> PaymentCallback([Required] string code, [FromBody] JObject value) { var(isSuccess, _, paymentResponse, error) = await _paymentLinksProcessingService.ProcessResponse(code, value); return(isSuccess ? Ok(paymentResponse) : (IActionResult)BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <IActionResult> GetBookingsToNotify([FromQuery] DateTime?date) { if (!date.HasValue) { return(BadRequest(ProblemDetailsBuilder.Build($"Date should be specified"))); } return(Ok(await _bookingsProcessingService.GetForNotification(date.Value))); }
public async Task <IActionResult> GetBookingsForCapture([FromQuery] DateTime?date) { if (date is null) { return(BadRequest(ProblemDetailsBuilder.Build("Date must be specified"))); } return(Ok(await _bookingsProcessingService.GetForCapture(date.Value))); }
public async Task <IActionResult> GetAppliedMarkupsForMaterialization([FromQuery] DateTime?date) { if (!date.HasValue) { return(BadRequest(ProblemDetailsBuilder.Build($"Date should be specified"))); } return(Ok(await _markupBonusMaterializationService.GetForMaterialize(date.Value))); }
public async Task <ActionResult <Booking> > Cancel(string clientReferenceCode) { var agent = await _agentContextService.GetAgent(); var(isSuccess, _, booking, error) = await _bookingCancellationService.Cancel(clientReferenceCode, agent); return(isSuccess ? booking : BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <ActionResult <Booking> > Get([Required] string clientReferenceCode) { var agent = await _agentContextService.GetAgent(); var(isSuccess, _, booking, error) = await _bookingInfoService.Get(clientReferenceCode, agent); return(isSuccess ? Ok(booking.FromEdoModels()) : BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <ActionResult <Booking> > Finalize([Required] string clientReferenceCode) { var agent = await _agentContextService.GetAgent(); var(isSuccess, _, booking, error) = await _bookingCreationService.Finalize(clientReferenceCode, agent, "en"); return(isSuccess ? Ok(booking) : BadRequest(ProblemDetailsBuilder.Build(error))); }
public async Task <ActionResult <Booking> > Register([FromBody] AccommodationBookingRequest request) { var agent = await _agentContextService.GetAgent(); var(isSuccess, _, booking, error) = await _bookingCreationService.Register(request, agent, "en"); return(isSuccess ? Ok(booking) : BadRequest(ProblemDetailsBuilder.Build(error))); }