private async Task Create(Poll poll) { using (var client = new HttpClient()) { var json = JsonConvert.SerializeObject(poll); client.BaseAddress = new Uri(_apiOptions.Url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var request = "/polls"; _logger.LogInformation($"{_apiOptions.Url}{request}"); _logger.LogInformation($"{json}"); var response = await client.PostAsync(request, new StringContent(json, System.Text.Encoding.UTF8,"application/json")); if (!response.IsSuccessStatusCode) { throw new Exception(); } } }
public async Task<IActionResult> Activate(Poll poll) { await _votingService.Activate(poll.Id); return RedirectToAction(nameof(PollController.Index)); }
public async Task<IActionResult> Create(Poll poll) { await _votingService.SaveOrUpdate(poll); return RedirectToAction(nameof(PollController.Index)); }
public async Task SaveOrUpdate(Poll poll) { await Create(poll); }