Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
 public async Task<IActionResult> Activate(Poll poll)
 {
     await _votingService.Activate(poll.Id);
     return RedirectToAction(nameof(PollController.Index));
 }
Ejemplo n.º 3
0
 public async Task<IActionResult> Create(Poll poll)
 {
     await _votingService.SaveOrUpdate(poll);
     return RedirectToAction(nameof(PollController.Index));
 }
Ejemplo n.º 4
0
 public async Task SaveOrUpdate(Poll poll)
 {
     await Create(poll);
 }