Ejemplo n.º 1
0
        public static void Seed(EvotingContext context)
        {
            var voterRepository     = new VoterRepository(context);
            var candidateRepository = new CandidateRepository(context);

            for (var i = 1; i <= 5; i++)
            {
                // Get a voter
                var voter = voterRepository.GetVoterById(i);

                // Get the constituency the voter is registered to
                var constituency = voter.Constituency;

                // Reoccur for three votes
                for (var t = 0; t < Preferential.MAX_VOTES; t++)
                {
                    // Get a random candidate in the list of candidates
                    var candidates = candidateRepository.GetCandidatesByConstituency(constituency);
                    var candidate  = candidates.ElementAt(Faker.RandomNumber.Next(1, candidates.Count()));

                    // Create a preferential vote
                    var vote = new Votes
                    {
                        Candidate = candidate,
                        Voter     = voter,
                        Priority  = (Priority)t
                    };
                    context.Votes.Add(vote);
                }
            }
            context.SaveChanges();
        }
        public ActionResult Edit(int id)
        {
            if (Session["EmailId"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            VoterRepository repo      = new VoterRepository();
            var             busEntity = voterRepository.FindVoter(id);

            Models.Voter voter = new Models.Voter()
            {
                VoterId      = busEntity.VoterId,
                VoterName    = busEntity.VoterName,
                Age          = busEntity.Age,
                DOB          = busEntity.DOB,
                Gender       = busEntity.Gender,
                City         = busEntity.City,
                State        = busEntity.State,
                EmailId      = busEntity.EmailId,
                MobileNumber = busEntity.MobileNumber
            };

            return(View(voter));
        }
        public ActionResult Create(Models.Voter voter)
        {
            if (Session["EmailId"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                DataAccess.Voter vInfo = new DataAccess.Voter()
                {
                    VoterName    = voter.VoterName,
                    Age          = voter.Age,
                    DOB          = voter.DOB,
                    Gender       = voter.Gender,
                    State        = voter.State,
                    City         = voter.City,
                    EmailId      = voter.EmailId,
                    MobileNumber = voter.MobileNumber
                };

                VoterRepository repo   = new VoterRepository();
                bool            result = repo.AddVoter(vInfo);

                if (!result)
                {
                    return(View("Error"));
                }
            }

            return(RedirectToAction("Index", "Voter"));
        }
        public ActionResult Edit(Models.Voter voter)
        {
            if (Session["EmailId"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            DataAccess.Voter eVoter = new DataAccess.Voter()
            {
                VoterId      = voter.VoterId,
                VoterName    = voter.VoterName,
                Age          = voter.Age,
                DOB          = voter.DOB,
                Gender       = voter.Gender,
                City         = voter.City,
                State        = voter.State,
                EmailId      = voter.EmailId,
                MobileNumber = voter.MobileNumber
            };

            VoterRepository repo   = new VoterRepository();
            bool            result = repo.UpdateVoterDetails(eVoter);

            if (!result)
            {
                return(View("Error"));
            }

            return(RedirectToAction("Index", "Voter"));
        }
        public ActionResult ConfirmDelete(int id)
        {
            if (Session["EmailId"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            VoterRepository repo   = new VoterRepository();
            bool            result = repo.DeleteVoterDetails(id);

            if (!result)
            {
                return(View("Error"));
            }

            return(RedirectToAction("Index", "Voter"));
        }
        public ActionResult Delete(int id)
        {
            VoterRepository repo    = new VoterRepository();
            var             bEntity = repo.FindVoter(id);

            Models.Voter voter = new Models.Voter()
            {
                VoterId      = bEntity.VoterId,
                VoterName    = bEntity.VoterName,
                Age          = bEntity.Age,
                DOB          = bEntity.DOB,
                Gender       = bEntity.Gender,
                City         = bEntity.City,
                State        = bEntity.State,
                EmailId      = bEntity.EmailId,
                MobileNumber = bEntity.MobileNumber
            };

            return(View(voter));
        }
Ejemplo n.º 7
0
        public VoterService()
        {
            this.VoterRepository = new Repository <Voter>();

            Voter voter1 = new Voter("jan", "jan", "jan", "jan", 52, Gender.MALE);
            Voter voter2 = new Voter("michal", "michal", "michal", "michal", 22, Gender.MALE);
            Voter voter3 = new Voter("mat", "mat", "mat", "mat", 34, Gender.OTHER);
            Voter voter4 = new Voter("wojt", "wojt", "wojt", "wojt", 19, Gender.MALE);
            Voter voter5 = new Voter("pat", "pat", "pat", "pat", 99, Gender.FEMALE);

            voter1.Id = 1;
            voter2.Id = 2;
            voter3.Id = 3;
            voter4.Id = 4;
            voter5.Id = 5;
            VoterRepository.addElement(1, voter1);
            VoterRepository.addElement(2, voter2);
            VoterRepository.addElement(3, voter3);
            VoterRepository.addElement(4, voter4);
            VoterRepository.addElement(5, voter5);
        }
Ejemplo n.º 8
0
 public VotersController()
 {
     _voterRepository = new VoterRepository(db);
 }