Example #1
0
        public IHttpActionResult PutVote(int id, Votes vote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != vote.Id)
            {
                return(BadRequest());
            }

            db.Entry(vote).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VoteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutParty(int id, Party party)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != party.Id)
            {
                return(BadRequest());
            }

            _db.Entry(party).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PartyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
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();
        }
Example #4
0
        public static void Seed(EvotingContext context)
        {
            const int count                  = 5;
            var       candidates             = new List <Candidate>();
            var       constituencyRepository = new ConstituencyRepository(context);
            var       partyRepository        = new PartyRepository(context);


            for (var i = 1; i <= count; i++)
            {
                var constituency = constituencyRepository.GetConstituencyById(Faker.RandomNumber.Next(1, 5));
                var party        = partyRepository.GetPartyById(Faker.RandomNumber.Next(1, 5));

                var candidate = new Candidate
                {
                    Constituency = constituency,
                    FirstName    = Faker.Name.First(),
                    LastName     = Faker.Name.Last(),
                    NumVotes     = 0,
                    Party        = party
                };
                candidates.Add(candidate);
            }
            candidates.ForEach(c => context.Candidates.Add(c));
            context.SaveChanges();
        }
        public static void Seed(EvotingContext context)
        {
            var constituencies = new List <Constituency>
            {
                new Constituency
                {
                    Name = Faker.Address.UkCounty(),
                },
                new Constituency
                {
                    Name = Faker.Address.UkCounty(),
                },
                new Constituency
                {
                    Name = Faker.Address.UkCounty()
                },
                new Constituency
                {
                    Name = Faker.Address.UkCounty()
                },
                new Constituency
                {
                    Name = Faker.Address.UkCounty()
                }
            };

            constituencies.ForEach(c => context.Constituencies.Add(c));
            context.SaveChanges();
        }
Example #6
0
        public static void Seed(EvotingContext context)
        {
            var now    = DateTime.Now;
            var end    = now.AddMonths(3);
            var config = new Config
            {
                StartDate = now,
                EndDate   = end,
                VoteType  = VoteType.Transferable
            };

            context.Config.Add(config);
            context.SaveChanges();

            switch (config.VoteType)
            {
            //case VoteType.FirstPass:
            //  FirstPastVotingSeed.Seed(context);
            //  break;
            case VoteType.Preferential:
                PreferentialVotingSeed.Seed(context);
                break;

            case VoteType.Transferable:
                TransferableVotingSeed.Seed(context);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #7
0
        public static void Seed(EvotingContext context)
        {
            var constituencyRepository = new ConstituencyRepository(context);
            var voters = new List <Voter>
            {
                new Voter
                {
                    FirstName    = Faker.Name.First(),
                    LastName     = Faker.Name.Last(),
                    Username     = Faker.Internet.UserName(),
                    Role         = Voter.ROLE,
                    Password     = "******",
                    Constituency = constituencyRepository.GetConstituencyById(Faker.RandomNumber.Next(1, 5))
                },
                new Voter
                {
                    FirstName    = Faker.Name.First(),
                    LastName     = Faker.Name.Last(),
                    Username     = Faker.Internet.UserName(),
                    Role         = Voter.ROLE,
                    Password     = "******",
                    Constituency = constituencyRepository.GetConstituencyById(Faker.RandomNumber.Next(1, 5))
                },
                new Voter
                {
                    FirstName    = Faker.Name.First(),
                    LastName     = Faker.Name.Last(),
                    Username     = Faker.Internet.UserName(),
                    Role         = Voter.ROLE,
                    Password     = "******",
                    Constituency = constituencyRepository.GetConstituencyById(Faker.RandomNumber.Next(1, 5))
                },
                new Voter
                {
                    FirstName    = Faker.Name.First(),
                    LastName     = Faker.Name.Last(),
                    Username     = Faker.Internet.UserName(),
                    Role         = Voter.ROLE,
                    Password     = "******",
                    Constituency = constituencyRepository.GetConstituencyById(Faker.RandomNumber.Next(1, 5))
                },
                new Voter
                {
                    FirstName    = Faker.Name.First(),
                    LastName     = Faker.Name.Last(),
                    Username     = Faker.Internet.UserName(),
                    Role         = Voter.ROLE,
                    Password     = "******",
                    Constituency = constituencyRepository.GetConstituencyById(Faker.RandomNumber.Next(1, 5))
                }
            };

            voters.ForEach(v => context.Users.Add(v));
            context.SaveChanges();
        }
Example #8
0
        public static void Seed(EvotingContext context)
        {
            var parties = new List <Party>
            {
                new Party
                {
                    Name      = "Conservative and Unionist Party",
                    Link      = "https://www.conservatives.com",
                    Manifesto = Faker.Lorem.Paragraphs(Faker.RandomNumber.Next(3, 5))
                },
                new Party
                {
                    Name      = "Labour Party",
                    Link      = "https://www.LabourParty.com",
                    Manifesto = Faker.Lorem.Paragraphs(Faker.RandomNumber.Next(3, 5))
                },
                new Party
                {
                    Name      = "Scottish National Party	",
                    Link      = "https://www.snp.org",
                    Manifesto = Faker.Lorem.Paragraphs(Faker.RandomNumber.Next(3, 5))
                },
                new Party
                {
                    Name      = "Liberal Democrats",
                    Link      = "https://www.libdems.org.uk/",
                    Manifesto = Faker.Lorem.Paragraphs(Faker.RandomNumber.Next(3, 5))
                },
                new Party
                {
                    Name      = "Democratic Unionist Party",
                    Link      = "www.mydup.com/",
                    Manifesto = Faker.Lorem.Paragraphs(Faker.RandomNumber.Next(3, 5))
                },
                new Party
                {
                    Name      = Faker.Company.Name(),
                    Link      = Faker.Internet.DomainName(),
                    Manifesto = Faker.Lorem.Paragraphs(Faker.RandomNumber.Next(3, 5))
                },
                new Party
                {
                    Name      = "Official Monster Raving Loony Party",
                    Link      = "https://www.omrlp.com/",
                    Manifesto = Faker.Lorem.Paragraphs(Faker.RandomNumber.Next(3, 5))
                },
            };

            parties.ForEach(v => context.Parties.Add(v));
            context.SaveChanges();
        }
Example #9
0
        public static void Seed(EvotingContext context)
        {
            var admins = new List <Admin>
            {
                new Admin
                {
                    FirstName = Faker.Name.First(),
                    LastName  = Faker.Name.Last(),
                    Username  = Faker.Internet.UserName(),
                    Password  = "******",
                    Role      = Admin.ROLE
                },
                new Admin
                {
                    FirstName = Faker.Name.First(),
                    LastName  = Faker.Name.Last(),
                    Username  = Faker.Internet.UserName(),
                    Password  = "******",
                    Role      = Admin.ROLE
                },
                new Admin
                {
                    FirstName = Faker.Name.First(),
                    LastName  = Faker.Name.Last(),
                    Username  = Faker.Internet.UserName(),
                    Password  = "******",
                    Role      = Admin.ROLE
                },
                new Admin
                {
                    FirstName = Faker.Name.First(),
                    LastName  = Faker.Name.Last(),
                    Username  = Faker.Internet.UserName(),
                    Password  = "******",
                    Role      = Admin.ROLE
                },
                new Admin
                {
                    FirstName = Faker.Name.First(),
                    LastName  = Faker.Name.Last(),
                    Username  = Faker.Internet.UserName(),
                    Password  = "******",
                    Role      = Admin.ROLE
                }
            };

            admins.ForEach(a => context.Users.Add(a));
            context.SaveChanges();
        }
 public void Save()
 {
     Context.SaveChanges();
 }