コード例 #1
0
        public async Task <IActionResult> PutPolitician([FromRoute] int id, [FromBody] Politician politician)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(politician).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PoliticianExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        private void ApplyPolicies()
        {
            var backups = _client.Get();

            if (backups == null || !backups.Any())
            {
                _logger.LogWarning("Backups not found.");
                return;
            }

            var currentDate = _clock.Now;
            var politician  = new Politician(backups, currentDate);

            var idsToRemove = politician.GetIdsToRemove();

            if (!idsToRemove.Any())
            {
                _logger.LogDebug($"Backups in actual state");
                return;
            }

            foreach (var id in idsToRemove)
            {
                _client.Remove(id);
                _logger.LogDebug($"Backup {id} was removed");
            }
        }
コード例 #3
0
        public Politician LoadPolitician(int id)
        {
            var politician = new Politician();

            using (var connection = new SqliteConnection(connectionString)) {
                using (var cmd = connection.CreateCommand()) {
                    connection.Open();

                    cmd.CommandText = String.Format("SELECT bioguide_id, first_name, last_name, govtrack_id, phone, state, party, address FROM Politician WHERE govtrack_id = '{0}'", id);

                    using (var reader = cmd.ExecuteReader()) {
                        if (reader.Read())
                        {
                            politician.FirstName     = reader ["first_name"].ToString();
                            politician.LastName      = reader ["last_name"].ToString();
                            politician.BioGuideId    = reader ["bioguide_id"].ToString();
                            politician.GovTrackId    = reader ["govtrack_id"].ToString();
                            politician.Phone         = reader ["phone"].ToString();
                            politician.State         = reader ["state"].ToString();
                            politician.Party         = reader ["party"].ToString();
                            politician.OfficeAddress = reader ["address"].ToString();
                        }
                    }
                }
            }
            return(politician);
        }
コード例 #4
0
 public void CreateNewPolitician(Politician politician)
 {
     if (!CheckPoliticianExist(politician))
     {
         db.Politician.Add(politician);
         db.SaveChanges();
     }
     else
     {
         /*if (!(politician.Contact == null))
          * {
          *  if (politician.Contact.Phone == null)
          *  {
          *      politician.Contact.Phone = "";
          *  }
          *  if (politician.Contact.Email == null)
          *  {
          *      politician.Contact.Email = "";
          *  }
          *  Politician politician1 = GetPolitician(politician);
          *  politician.Contact.PoliticianId = politician1.Id;
          *  db.ContactInfos.InsertOnSubmit(politician.Contact);
          *  db.SubmitChanges();*/
     }
 }
コード例 #5
0
        /// <summary>
        /// 政治人物名單寫入
        /// </summary>
        /// <param name="politician"></param>
        public void InsertPolitician(Politician politician)
        {
            using (News_DatabaseEntities _nDB = new News_DatabaseEntities())
            {
                PoliticianTable _politician = new PoliticianTable
                {
                    //ID取Key值
                    Id     = Guid.NewGuid(),
                    Name   = politician.Name,
                    Amount = politician.Amount,
                };


                try
                {
                    if (!_nDB.PoliticianTable.Any(b => b.Name == _politician.Name))
                    {
                        _nDB.PoliticianTable.Add(_politician);
                        _nDB.SaveChanges();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #6
0
    public void election()
    {
        //Pick a random candidate if one was not selected.
        if (!selected)
        {
            chosenCandidate = candidates [Random.Range(0, candidates.Count)];
        }

        Politician op;

        op.cost            = 0;
        op.bizModifier     = chosenCandidate.bizModifier * -1;
        op.civModifier     = chosenCandidate.civModifier * -1;
        op.name            = alphabet [Random.Range(0, alphabet.Length)] + alphabet [Random.Range(0, alphabet.Length)];
        op.chanceOfWinning = 1.0f - chosenCandidate.chanceOfWinning;

        int chance = Random.Range(0, 100);

        if (chance <= (chosenCandidate.chanceOfWinning * 100))
        {
            winner = chosenCandidate;
            Debug.Log("WINNER: And the Winner for " + this.name + " is: " + winner.name);
        }
        else
        {
            winner = op;
            Debug.Log("LOSER: And the Winner for " + this.name + " is: " + winner.name);
        }

        districtAffiliation += winner.bizModifier;
        districtAffiliation -= winner.civModifier;

        distBizAff = districtAffiliation;
        distCivAff = 100 - districtAffiliation;
    }
コード例 #7
0
        public void Politician_PrepareToBackup_ActualCheck()
        {
            var politician = new Politician(BackupRecords.ActualBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();
            var actualIds   = BackupRecords.ActualBackups
                              .Select(x => x.Id)
                              .Except(idsToRemove)
                              .ToArray();

            var expected = new[]
            {
                // 0 gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd18"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd20"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd21"),

                // 1st gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd26"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd28"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd29"),

                // 2nd gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd34"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd36"),
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd37"),

                // 3th gen
                new Guid("53afa98d-c280-4ee3-8228-79dcd4c3dd48")
            };

            actualIds.Should().BeEquivalentTo(expected);
        }
コード例 #8
0
ファイル: DBService.cs プロジェクト: hamzah0553/FTClient
 public void AddPolitician(Politician politician)
 {
     using (var context = new FTDatabaseEntities())
     {
         context.Politician.Add(politician);
         context.SaveChanges();
     }
 }
コード例 #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            Politician politician = db.Politicians.Find(id);

            db.Politicians.Remove(politician);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #10
0
        public void newPolitician_checkId_shouldBeZero()
        {
            Politician f = new Politician
            {
            };

            Assert.That(f.Id, Is.EqualTo(0));
        }
コード例 #11
0
        public ActionResult Create(Politician politician)
        {
            //設定0
            politician.Amount = 0;

            _orderLibrary.SavePolitician(politician);

            return(RedirectToAction("PoliticianView"));
        }
コード例 #12
0
 public static void QuickSort(ref Politician[] input, int left, int right)
 {
     if (left < right)
     {
         int q = Partition(ref input, left, right);
         QuickSort(ref input, left, q - 1);
         QuickSort(ref input, q + 1, right);
     }
 }
コード例 #13
0
 public ActionResult Edit([Bind(Include = "PoliticianID,Name")] Politician politician)
 {
     if (ModelState.IsValid)
     {
         db.Entry(politician).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(politician));
 }
コード例 #14
0
        public ActionResult Create([Bind(Include = "PoliticianID,Name")] Politician politician)
        {
            if (ModelState.IsValid)
            {
                db.Politicians.Add(politician);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(politician));
        }
コード例 #15
0
    public Politician GetCandidateAt(int i)
    {
        Politician p = null;

        if (candidates.Count > 2)
        {
            GameObject g = GetLocalInstance(candidates [i].id);
            p = g.GetComponent <Politician> ();
        }
        return(p);
    }
コード例 #16
0
    public void SpawnPolitician(int p, Region r)
    {
        GameObject spawnPoint  = bus [Random.Range(0, bus.Length - 1)];
        GameObject newResident = (GameObject)Instantiate(Resources.Load("Politician"), spawnPoint.transform.position, Quaternion.identity);
        Politician tmp         = newResident.GetComponent <Politician> ();

        tmp.party      = p;
        tmp.runningFor = r;
        NetworkServer.Spawn(newResident);
        residents.Add(tmp);
    }
コード例 #17
0
 public void CreateNewPolitician(Politician politician, ContactInfo contact)
 {
     if (!CheckPoliticianExist(politician))
     {
         db.Politician.Add(politician);
         db.SaveChanges();
     }
     if (true)
     {
     }
 }
コード例 #18
0
        public async Task <IActionResult> PostPolitician([FromBody] Politician politician)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Politician.Add(politician);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPolitician", new { id = politician.Id }, politician));
        }
コード例 #19
0
    static void Main()
    {
        JZ         jz    = new JZ("JZ", 100, "Male", "politician", "ANC");
        Politician helen = new Politician("Helen Zille", 60, "Female", "politician", "DA");
        Politician juju  = new Politician("Juju", 40, "Male", "politician", "EFF");

        Nkandla nkandla = new Nkandla("Nkandla", "Zumaville", "State of Zuma", "SA");

        nkandla.accept(jz);
        nkandla.accept(helen);
        nkandla.accept(juju);
    }
コード例 #20
0
 public void HybridSort(Politician[] input)
 {
     for (int i = 0; i < input.Length; i++)
     {
         for (int j = input.Length - 1; j > i; j--)
         {
             if (input[i].votes < input[j].votes)
             {
                 Swap(ref input[i], ref input[j]);
             }
         }
     }
 }
コード例 #21
0
        public void Politician_ObsoleteRemoved()
        {
            var politician = new Politician(BackupRecords.TwoWeekBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();
            var actualIds   = BackupRecords.TwoWeekBackups
                              .Select(x => x.Id)
                              .Except(idsToRemove)
                              .ToArray();

            idsToRemove.Should().HaveCount(22);
            actualIds.Should().HaveCount(10);
        }
コード例 #22
0
        public void Politician_PrepareToBackup()
        {
            var politician = new Politician(BackupRecords.ActualBackups, BackupRecords.CurrentDate);

            var idsToRemove = politician.GetIdsToRemove();
            var actualIds   = BackupRecords.ActualBackups
                              .Select(x => x.Id)
                              .Except(idsToRemove)
                              .ToArray();

            idsToRemove.Should().HaveCount(3);
            actualIds.Should().HaveCount(10);
        }
コード例 #23
0
        public bool CheckPoliticianExist(Politician politician)
        {
            var newPol = GetPolitician(politician.firstname, politician.lastname);

            if (newPol == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #24
0
ファイル: ParliamentVM.cs プロジェクト: hamzah0553/FTClient
        //Edit function for parliament members
        public string EditMember(CustomPolitcian politcian)
        {
            string     msg = "";
            Politician selectedPolitician = entities.Politician.Where(p => p.id == politcian.PoliticianId).SingleOrDefault();

            selectedPolitician.firstname = politcian.Firstname;
            selectedPolitician.lastname  = politcian.Lastname;
            selectedPolitician.partyId   = entities.Party.Where(p => p.name.Equals(politcian.Party)).SingleOrDefault().id;
            selectedPolitician.ContactInfo.SingleOrDefault().phone = politcian.Phone;
            selectedPolitician.ContactInfo.SingleOrDefault().email = politcian.Email;
            entities.SaveChanges();

            return(msg);
        }
コード例 #25
0
        // GET: Politicians/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Politician politician = db.Politicians.Find(id);

            if (politician == null)
            {
                return(HttpNotFound());
            }
            return(View(politician));
        }
コード例 #26
0
    private void SpawnPanel()
    {
        Region     r      = p.targetObject.GetComponent <CityHall> ().governedRegion;
        Politician teal   = r.GetCandidateAt(0);
        Politician grey   = r.GetCandidateAt(1);
        Politician yellow = r.GetCandidateAt(2);

        GameObject prefab = (GameObject)Resources.Load("uiElements/ElectionPanel");

        panel = (GameObject)Instantiate(prefab);
        panel.transform.SetParent(GameObject.Find("Canvas").transform, false);
        panel.transform.Find("TealImg").transform.Find("Body").GetComponent <Text> ().text   = teal.ElectionFormatString();
        panel.transform.Find("GreyImg").transform.Find("Body").GetComponent <Text> ().text   = grey.ElectionFormatString();
        panel.transform.Find("YellowImg").transform.Find("Body").GetComponent <Text> ().text = yellow.ElectionFormatString();
    }
コード例 #27
0
        public void createPolitician_byDefault_shouldThrowException()
        {
            Politician f = new Politician
            {
            };

            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(f.Id == 0);

                    Assert.Throws <NHibernate.PropertyValueException>(() => session.SaveOrUpdate(f));
                }
            }
        }
コード例 #28
0
        public Politician GetPolitician(Politician politician)
        {
            Politician newPolitician;
            var        result = from pol in db.Politician
                                where pol.firstname.Equals(politician.firstname) && pol.lastname.Equals(politician.lastname)
                                select pol;

            if (result.Any())
            {
                newPolitician = result.First();
                return(newPolitician);
            }
            else
            {
                return(null);
            }
        }
コード例 #29
0
ファイル: GovernmentVM.cs プロジェクト: hamzah0553/FTClient
        //Add Minister to db
        public void AddMinisters()
        {
            using (var entities = new FTDatabaseEntities())
            {
                MinisterScraper        scraper   = new MinisterScraper();
                List <ExtractedValues> values    = scraper.GetMinisters();
                List <CustomMinister>  ministers = new List <CustomMinister>();
                foreach (var item in values)
                {
                    Politician politician = service.GetPolitician(item.Firstname, item.Lastname);
                    if (politician == null)
                    {
                        politician           = new Politician();
                        politician.firstname = item.Firstname;
                        politician.lastname  = item.Lastname;
                        politician.partyId   = entities.Party.Where(p => p.name.Equals(item.Party)).SingleOrDefault().id;
                        service.AddPolitician(politician);

                        politician = service.GetPolitician(item.Firstname, item.Lastname);
                        ContactInfo contactInfo = item.Contact;
                        contactInfo.politicianId = politician.id;
                        Debug.WriteLine(politician.id);
                        service.AddContactInfo(contactInfo);
                    }
                    MinisterialPost post = service.GetMinisterialPost(item.Title);
                    if (post == null)
                    {
                        using (var context = new FTDatabaseEntities())
                        {
                            context.MinisterialPost.Add(new MinisterialPost()
                            {
                                governmentId = 1, title = item.Title
                            });
                            context.SaveChanges();
                        }
                    }
                    Minister minister = new Minister();
                    minister.ministerialPostId = service.GetMinisterialPost(item.Title).id;
                    minister.politicianId      = politician.id;
                    minister.startDate         = DateTime.Now.Date;
                    entities.Minister.Add(minister);
                }
                entities.SaveChanges();
            }
        }
コード例 #30
0
    public TimedMethod[] Recover()
    {
        SetAlive(false);
        Party.enemyCount--;
        Party.enemySlot = 1;
        Politician pol = (Politician)Party.enemies[0];

        pol.broken = false;
        pol.cycle  = 4;
        Status.NullifyAttack(pol);
        Status.NullifyDefense(pol);
        return(new TimedMethod[] { new TimedMethod(0, "Audio", new object[] { "Finale" }), new TimedMethod(0, "AudioAfter", new object[] { "Nullify", 30 }),
                                   new TimedMethod(60, "Log", new object[] { ToString() + " Caused the politician's grand return" }),
                                   new TimedMethod(0, "CharLogSprite", new object[] { "10", Party.enemySlot - 1, "charge", false }),
                                   new TimedMethod(0, "CharLogSprite", new object[] { "Atk Reset", Party.enemySlot - 1, "nullAttack", false }),
                                   new TimedMethod(0, "CharLogSprite", new object[] { "Def Reset", Party.enemySlot - 1, "nullDefense", false }),
                                   new TimedMethod(0, "EnemySwitch", new object[] { 1, 2 }) });
    }
コード例 #31
0
        public void AddMayors(List <CustomMayor> mayors)
        {
            using (var entity = new FTDatabaseEntities())
            {
                List <CustomMayor> ministers = new List <CustomMayor>();

                foreach (var item in mayors)
                {
                    Politician politician = service.GetPolitician(item.Firstname, item.Lastname);
                    if (politician == null)
                    {
                        politician           = new Politician();
                        politician.firstname = item.Firstname;
                        politician.lastname  = item.Lastname;
                        politician.partyId   = entity.Party.Where(p => p.name.Equals(item.Party)).SingleOrDefault().id;
                        service.AddPolitician(politician);

                        politician = service.GetPolitician(item.Firstname, item.Lastname);
                        ContactInfo contactInfo = new ContactInfo();
                        contactInfo.email        = item.Email;
                        contactInfo.phone        = item.Phone;
                        contactInfo.politicianId = politician.id;
                        service.AddContactInfo(contactInfo);
                    }
                    Municipality municipality = service.GetMunicipality(item.Municipality);
                    if (municipality == null)
                    {
                        using (var context = new FTDatabaseEntities())
                        {
                            context.Municipality.Add(new Municipality()
                            {
                                regionId = 1, name = item.Municipality
                            });
                            context.SaveChanges();
                        }
                    }
                    Mayor mayor = new Mayor();
                    mayor.politicianId   = politician.id;
                    mayor.municipalityId = service.GetMunicipality(item.Municipality).id;
                    entity.Mayor.Add(mayor);
                }
                entity.SaveChanges();
            }
        }
コード例 #32
0
 public void SelectCandidate(int num)
 {
     if (MH.playerResourceAmount > candidates [num].cost && !selected)
     {
         chosenCandidate          = candidates [num];
         candidatesText.text      = chosenCandidate.name + " Has been chosen for this election.";
         selected                 = true;
         MH.playerResourceAmount -= candidates [num].cost;
         foreach (Button b in selectButtons)
         {
             Destroy(b);
             b.GetComponent <Image> ().enabled = false;
             b.transform.GetChild(0).GetComponent <Text> ().enabled = false;
         }
     }
     else
     {
         Debug.Log("Not enough money!");
     }
 }
コード例 #33
0
ファイル: Paragraf20.cs プロジェクト: friism/folketsting
 private static Politician CheckForPolitian(string name, string party, string pollink, ScrapeDBDataContext db)
 {
     Politician pol;
     lock (pollock)
     {
         using (TransactionScope ts = new TransactionScope())
         {
             pol = db.Politicians.SingleOrDefault(p => p.Name == name);
             if (pol != null)
             {
             }
             else
             {
                 pol = new Politician { Name = name, PartyString = party, };
                 db.Politicians.InsertOnSubmit(pol);
                 db.SubmitChanges();
                 Console.WriteLine("           Created politker {0}", name);
             }
             ts.Complete();
         }
     }
     return pol;
 }
コード例 #34
0
 private Politician GetPolitician(ImporterResultRowsAggregated aggregatedRow)
 {
     var politician = new Politician();
     politician.Capacity = aggregatedRow.GetPoliticalFunction();
     politician.Email = aggregatedRow.GetEmail();
     politician.Location = aggregatedRow.GetLocation();
     politician.Name = aggregatedRow.GetName();
     politician.Url = aggregatedRow.GetUrl();
     return politician;
 }
コード例 #35
0
 public VotesPerOffice(Politician[] office)
 {
     this.office = office;
 }
コード例 #36
0
 static void Swap(ref Politician a, ref Politician b)
 {
     Politician temp = a;
     a = b;
     b = temp;
 }
コード例 #37
0
        static int Partition(ref Politician[] input, int left, int right)
        {
            Politician pivot = input[right];
            int i = left;

            for (int j = left; j < right; j++)
            {
                if (input[j].votes > pivot.votes)
                    Swap(ref input[j], ref input[i++]);
            }
            input[right] = input[i];
            input[i] = pivot;
            return i;
        }
コード例 #38
0
 private static Politician[] CentralizeVotes(VotesPerOffice[] results)
 {
     Politician[] total = new Politician[results[0].office.Length];
     for (int i = 0; i < total.Length; i++)
     {
         total[i].name = results[0].office[i].name;
         total[i].votes = 0;
     }
     return total;
 }
コード例 #39
0
 public static void Save(Politician politician)
 {
     Collection.Save(politician);
 }