public async Task <IActionResult> FindAll() { AVSContext avsDBContext = new AVSContext(); var voterList = avsDBContext.TblVoter.ToList(); return(Ok(voterList)); }
public async Task <IActionResult> FindAll() { AVSContext avsDBContext = new AVSContext(); var candidateList = avsDBContext.TblCandidate.ToList(); return(Ok(candidateList)); }
public Tab2Controller(AVSContext context) { _context = context; if (!_context.Tab2.Any()) { var provider = new Provider(_context); provider.GetDataTab2(); } }
public HTMLController(AVSContext context) { db = context; if (!db.Tab2.Any()) { var provider = new Provider(db); provider.GetDataTab2(); } }
public async Task <IActionResult> Create([FromBody] TblVoter voter) { if (voter.Age < 18) { return(BadRequest("Voter is not eligible to vote !")); } else { AVSContext avsDBContext = new AVSContext(); avsDBContext.TblVoter.Add(voter); avsDBContext.SaveChanges(); return(Ok(voter)); } }
public async Task <IActionResult> Create([FromBody] TblCategory category) { try { AVSContext avsDBContext = new AVSContext(); avsDBContext.TblCategory.Add(category); avsDBContext.SaveChanges(); return(Ok(category)); } catch (Exception ex) { return(BadRequest("Invalid input data!")); } }
public async Task <IActionResult> DoVote([FromBody] List <TblVoterDetail> votes) { List <VotingDTO> lstErrors = new List <VotingDTO>(); using (AVSContext avsDBContext = new AVSContext()) { using (IDbContextTransaction transaction = avsDBContext.Database.BeginTransaction()) { try { foreach (TblVoterDetail vote in votes) { var existingVoter = avsDBContext.TblVoter.Where(x => x.Id == vote.Vid).FirstOrDefault(); var existingCandidate = avsDBContext.TblCandidate.Where(x => x.Id == vote.Cid).FirstOrDefault(); if (existingVoter == null || existingCandidate == null) { lstErrors.Add(new VotingDTO { CID = vote.Cid, IsValid = false, VID = vote.Vid }); } var voteExists = avsDBContext.TblVoterDetail.Where(x => x.Vid == vote.Vid && x.Cid == vote.Cid); if (voteExists != null) { avsDBContext.TblVoterDetail.Add(vote); avsDBContext.SaveChanges(); } } if (lstErrors.Count > 0) { transaction.Rollback(); return(Content("Invalid voting!")); } else { transaction.Commit(); } return(Ok("Successfully Voted!")); } catch (Exception ex) { transaction.Rollback(); return(BadRequest("Issue with the Voting!")); } } } }
public async Task <IActionResult> voterById(int id) { try { AVSContext avsDBContext = new AVSContext(); var v = avsDBContext.TblVoter.Where(x => x.Id == id); if (v == null) { return(NotFound("Voter doesn't exist!")); } else { return(Ok(v)); } } catch (Exception ex) { return(BadRequest("Input data is not correct")); } }
public async Task <IActionResult> Create([FromBody] TblCandidate candidate) { try { AVSContext avsDBContext = new AVSContext(); var category = avsDBContext.TblCategory.Where(x => x.Id == candidate.CategoryId).FirstOrDefault(); if (category == null) { return(NotFound("Category not found!")); } else { avsDBContext.TblCandidate.Add(candidate); avsDBContext.SaveChanges(); return(Ok(candidate)); } } catch (Exception ex) { return(BadRequest("Invalid input data!")); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new AVSContext( serviceProvider.GetRequiredService < DbContextOptions <AVSContext> >())) { if (!context.Tab1.Any()) { context.Tab1.AddRange( new Tab1 { KEY = 1, VALUE = 1 }, new Tab1 { KEY = 1, VALUE = 2 }, new Tab1 { KEY = 1, VALUE = 3 }, new Tab1 { KEY = 2, VALUE = 1 }, new Tab1 { KEY = 2, VALUE = 3 }, new Tab1 { KEY = 2, VALUE = 1 }, new Tab1 { KEY = 2, VALUE = 1 } ); context.SaveChanges(); } return; } }
public Provider(AVSContext context) { Db = context; }
public DetailsModel(AVSContext context) { _context = context; }
public EditModel(AVSContext context) { _context = context; }
public CreateModel(AVSContext context) { _context = context; }
public IndexModel(AVSContext context) { _context = context; }
public DeleteModel(AVSContext context) { _context = context; }