コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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());
        }