// GET: Voters/Delete/5 public async Task<IActionResult> Delete(string id) { ElectionWinner winner = await _winner.GetElectionWinnerById(id); if (winner == null) { return NotFound(); } return View(winner); }
public async Task AddElectionWinner(ElectionWinner winner) { try { _ctx.ElectionWinners.Update(winner); await _ctx.SaveChangesAsync(); return; } catch (Exception ex) { _logger.LogInformation($"There was an error {ex.Message}"); } }
public async Task<IActionResult> Create(ElectionWinner winner) { if (!ModelState.IsValid) { return RedirectToAction(nameof(Create)); } try { await _winner.AddElectionWinner(winner); return RedirectToAction(nameof(Index)); } catch { return View(nameof(HomeController.Error)); } }
public async Task <bool> UpdateElectionWinnerById(ElectionWinner electionWinner) { if (ElectionWinnerExists(electionWinner.ElectionWinnerId)) { try { _ctx.ElectionWinners.Update(electionWinner); await _ctx.SaveChangesAsync(); return(true); } catch (Exception ex) { _logger.LogInformation($"There was an error {ex.Message}"); return(false); } } return(false); }
public async Task<IActionResult> Edit(string id, ElectionWinner winner) { if (id != winner.ElectionWinnerId) { return RedirectToAction(nameof(Edit), new { id }); } if (!ModelState.IsValid) { return RedirectToAction(nameof(Edit), new { id }); } try { await _winner.UpdateElectionWinnerById(winner); return RedirectToAction(nameof(Index)); } catch { return View(nameof(HomeController.Error)); } }
public async Task <bool> DeleteElectionWinner(string id) { if (ElectionWinnerExists(id)) { try { ElectionWinner electionWinner = await _ctx.ElectionWinners.FindAsync(id); _ctx.ElectionWinners.Remove(electionWinner); await _ctx.SaveChangesAsync(); return(true); } catch (Exception ex) { _logger.LogInformation($"There was an error {ex.Message}"); return(false); } } return(false); }