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()); }
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"); } }
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); }
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();*/ } }
/// <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; } } }
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; }
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); }
public void AddPolitician(Politician politician) { using (var context = new FTDatabaseEntities()) { context.Politician.Add(politician); context.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { Politician politician = db.Politicians.Find(id); db.Politicians.Remove(politician); db.SaveChanges(); return(RedirectToAction("Index")); }
public void newPolitician_checkId_shouldBeZero() { Politician f = new Politician { }; Assert.That(f.Id, Is.EqualTo(0)); }
public ActionResult Create(Politician politician) { //設定0 politician.Amount = 0; _orderLibrary.SavePolitician(politician); return(RedirectToAction("PoliticianView")); }
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); } }
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)); }
public ActionResult Create([Bind(Include = "PoliticianID,Name")] Politician politician) { if (ModelState.IsValid) { db.Politicians.Add(politician); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(politician)); }
public Politician GetCandidateAt(int i) { Politician p = null; if (candidates.Count > 2) { GameObject g = GetLocalInstance(candidates [i].id); p = g.GetComponent <Politician> (); } return(p); }
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); }
public void CreateNewPolitician(Politician politician, ContactInfo contact) { if (!CheckPoliticianExist(politician)) { db.Politician.Add(politician); db.SaveChanges(); } if (true) { } }
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)); }
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); }
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]); } } } }
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); }
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); }
public bool CheckPoliticianExist(Politician politician) { var newPol = GetPolitician(politician.firstname, politician.lastname); if (newPol == null) { return(false); } else { return(true); } }
//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); }
// 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)); }
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(); }
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)); } } }
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); } }
//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(); } }
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 }) }); }
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(); } }
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!"); } }
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; }
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; }
public VotesPerOffice(Politician[] office) { this.office = office; }
static void Swap(ref Politician a, ref Politician b) { Politician temp = a; a = b; b = temp; }
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; }
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; }
public static void Save(Politician politician) { Collection.Save(politician); }