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));
        }
示例#3
0
 public Tab2Controller(AVSContext context)
 {
     _context = context;
     if (!_context.Tab2.Any())
     {
         var provider = new Provider(_context);
         provider.GetDataTab2();
     }
 }
示例#4
0
 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!"));
     }
 }
示例#7
0
        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!"));
     }
 }
示例#10
0
 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;
     }
 }
示例#11
0
 public Provider(AVSContext context)
 {
     Db = context;
 }
示例#12
0
 public DetailsModel(AVSContext context)
 {
     _context = context;
 }
示例#13
0
 public EditModel(AVSContext context)
 {
     _context = context;
 }
示例#14
0
 public CreateModel(AVSContext context)
 {
     _context = context;
 }
示例#15
0
 public IndexModel(AVSContext context)
 {
     _context = context;
 }
示例#16
0
 public DeleteModel(AVSContext context)
 {
     _context = context;
 }