Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ClientId,ClientSecret,AccessToken,ExpiryTime,IsActive")] SabreCredential sabreCredential)
        {
            if (id != sabreCredential.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sabreCredential);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SabreCredentialExists(sabreCredential.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(sabreCredential));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,ClientId,ClientSecret,AccessToken,ExpiryTime,IsActive")] SabreCredential sabreCredential)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sabreCredential);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sabreCredential));
        }
Beispiel #3
0
        private async Task <AccessToken> GetAccessTokenAsync()
        {
            AccessToken accessToken = null;

            SabreCredential sabreCredential = await GetSabreCredentialAsync();

            string json = await RequestAccessTokenAsync(
                sabreCredential.ClientId,
                sabreCredential.ClientSecret);

            var token = JsonConvert.DeserializeObject <dynamic>(json);

            if (token?.error == null)
            {
                accessToken = new AccessToken
                {
                    Token      = token.access_token,
                    ExpiryTime = DateTime.Now.AddSeconds((int)token.expires_in).AddMinutes(-15)
                };
            }
            ;

            return(accessToken);
        }