public async Task <IActionResult> PutTornApiKey(int id, TornApiKey tornApiKey) { if (id != tornApiKey.PlayerId) { return(BadRequest()); } _context.Entry(tornApiKey).State = EntityState.Modified; try { await _context.SaveChangesAsync().ConfigureAwait(false); } catch (DbUpdateConcurrencyException ex) { _logger.LogError(ex, "Error attempting to PUT {0}", id); if (!TornApiKeyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TornApiKey> > PostTornApiKey(TornApiKey tornApiKey) { _context.TornApiKey.Add(tornApiKey); await _context.SaveChangesAsync().ConfigureAwait(false); return(CreatedAtAction("GetTornApiKey", new { id = tornApiKey.PlayerId }, tornApiKey)); }
public async Task <IActionResult> Edit(int id, [Bind("ApiKey,Enabled,TrackPlayer,TrackFaction,TrackCompany,TrackTorn")] TornApiKey tornApiKey) { if (id != tornApiKey.PlayerId) { return(NotFound()); } if (ModelState.IsValid) { tornApiKey = await VerifyApiKey(tornApiKey).ConfigureAwait(false); try { _context.Update(tornApiKey); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TornApiKeyExists(tornApiKey.PlayerId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tornApiKey)); }
private async Task <TornApiKey> VerifyApiKey(TornApiKey tornApiKey) { var user = await _client.GetUserDataAsync(tornApiKey.ApiKey, Comment : "TC Pro").ConfigureAwait(false); tornApiKey.PlayerId = user.PlayerId; tornApiKey.FactionId = user.Faction.FactionId; tornApiKey.CompanyId = user.Job.CompanyId; return(tornApiKey); }
public async Task <IActionResult> Create([Bind("ApiKey,Enabled,TrackPlayer,TrackFaction,TrackCompany,TrackTorn")] TornApiKey tornApiKey) { if (ModelState.IsValid) { // Verify API Key tornApiKey = await VerifyApiKey(tornApiKey).ConfigureAwait(false); _context.Add(tornApiKey); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tornApiKey)); }