public async Task <ActionResult <PexValidityModel> > Validity(string sessionId, CancellationToken cancellationToken) { if (!Guid.TryParse(sessionId, out var sessionGuid)) { return(BadRequest()); } var session = await _pexOAuthSessionStorage.GetBySessionGuidAsync(sessionGuid, cancellationToken); if (session == null) { return(Unauthorized()); } var mapping = await _pex2AplosMappingStorage.GetByBusinessAcctIdAsync(session.PEXBusinessAcctId, cancellationToken); if (mapping == null) { return(NotFound()); } var isTagsEnabled = await _pexApiClient.IsTagsEnabled(mapping.PEXExternalAPIToken, cancellationToken); var result = new PexValidityModel { UseTagsEnabled = isTagsEnabled }; return(result.IsValid ? Ok(result) : StatusCode(StatusCodes.Status403Forbidden, result)); }
public async Task <ActionResult <IEnumerable <PexAplosApiObject> > > GetAccounts(string sessionId, string category, CancellationToken cancellationToken) { if (!Guid.TryParse(sessionId, out var sessionGuid)) { return(BadRequest()); } var session = await _pexOAuthSessionStorage.GetBySessionGuidAsync(sessionGuid, cancellationToken); if (session == null) { return(Unauthorized()); } var mapping = await _pex2AplosMappingStorage.GetByBusinessAcctIdAsync(session.PEXBusinessAcctId, cancellationToken); if (mapping == null) { return(NotFound()); } var accounts = await _aplosIntegrationService.GetAplosAccounts(mapping, category, cancellationToken); return(Ok(accounts)); }
public async Task <ActionResult> CreateAplosToken(string sessionId, [FromBody] AplosTokenRequestModel model, CancellationToken cancellationToken) { if (!Guid.TryParse(sessionId, out var sessionGuid)) { return(BadRequest()); } PexOAuthSessionModel session = await _pexOAuthSessionStorage.GetBySessionGuidAsync(sessionGuid, cancellationToken); if (session == null) { return(Unauthorized()); } Pex2AplosMappingModel mapping = await _pex2AplosMappingStorage.GetByBusinessAcctIdAsync(session.PEXBusinessAcctId, cancellationToken); if (!string.IsNullOrWhiteSpace(model.AplosClientId)) { mapping.AplosClientId = model.AplosClientId; } if (!string.IsNullOrWhiteSpace(model.AplosPrivateKey)) { mapping.AplosPrivateKey = model.AplosPrivateKey; } bool result = await _aplosIntegrationService.ValidateAplosApiCredentials(mapping, cancellationToken); if (!result) { return(BadRequest()); } await _pex2AplosMappingStorage.UpdateAsync(mapping, cancellationToken); return(Ok()); }
public async Task <IActionResult> SaveSettings(string sessionId, [FromBody] MappingSettingsModel settings, CancellationToken cancellationToken) { if (!Guid.TryParse(sessionId, out var sessionGuid)) { return(BadRequest()); } var session = await _pexOAuthSessionStorage.GetBySessionGuidAsync(sessionGuid, cancellationToken); if (session == null) { return(Unauthorized()); } var pexAcctId = session.PEXBusinessAcctId; var mapping = await _pex2AplosMappingStorage.GetByBusinessAcctIdAsync(pexAcctId, cancellationToken); mapping.UpdateFromSettings(settings); await _pex2AplosMappingStorage.UpdateAsync(mapping, cancellationToken); return(Ok()); }