Example #1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     curCont = new ElectionContext();
     curCont.Candidates.Load();
     curCont.Confidents.Load();
     infoGrid.ItemsSource = curCont.Candidates.Local.ToBindingList();
     secGrid.ItemsSource  = curCont.Confidents.Local.ToBindingList();
     this.Closing        += Window_Closing;
 }
Example #2
0
 public MainWindow()
 {
     using (ElectionContext db = new ElectionContext())
     {
         Candidate c1 = new Candidate {
             Name = "Alex", Surname = "Lukashenko", Rating = 35
         };
         Candidate c2 = new Candidate {
             Name = "Zianon", Surname = "Pozniak", Rating = 65
         };
         Candidate c3 = new Candidate {
             Name = "Maria", Surname = "Vasilevish", Rating = 0
         };
         db.Candidates.AddRange(new List <Candidate>()
         {
             c1, c2, c3
         });
         Confident conf1 = new Confident {
             FullName = "Alex Matskevich", Age = 40, PoliticalPreferences = "Neutral", Candidate = c1
         };
         Confident conf2 = new Confident {
             FullName = "Karyna Kluchnik", Age = 18, PoliticalPreferences = "Monarch", Candidate = c2
         };
         Confident conf3 = new Confident {
             FullName = "Tanya Verbovich", Age = 25, PoliticalPreferences = "Liberal", Candidate = c2
         };
         db.Confidents.AddRange(new List <Confident>()
         {
             conf1, conf2, conf3
         });
         Promise prom1 = new Promise {
             Text = "Stop War"
         };
         Promise prom2 = new Promise {
             Text = "Increase revenue"
         };
         prom1.Candidates.Add(c1);
         prom2.Candidates.Add(c1);
         prom2.Candidates.Add(c2);
         db.Promises.AddRange(new List <Promise> {
             prom1, prom2
         });
         db.SaveChanges();
         CandidateProfile prof1 = new CandidateProfile {
             Id = c1.Number, Age = 50, Description = "Current president"
         };
         CandidateProfile prof2 = new CandidateProfile {
             Id = c2.Number, Age = 40, Description = "Legend"
         };
         db.CandidateProfiles.AddRange(new List <CandidateProfile> {
             prof1, prof2
         });
         db.SaveChanges();
     }
     InitializeComponent();
 }
Example #3
0
 private void updRating_Click(object sender, RoutedEventArgs e)
 {
     using (ElectionContext db = new ElectionContext())
     {
         var result2 = db.Candidates.Join(db.Confidents, p => p.Number,
                                          c => c.CandidateId, (p, c) => new
         {
             Name             = c.FullName,
             CandidateSurname = p.Surname
         }
                                          ).ToList();
         infoGrid.ItemsSource = result2;
         var result3 = db.Confidents.GroupBy(c => c.CandidateId).Select(g =>
                                                                        new { ID = g.FirstOrDefault().Id, AvgAge = g.Average(c => c.Age) }).Join(db.Candidates,
                                                                                                                                                 a => a.ID,
                                                                                                                                                 b => b.Number, (a, b) => new
         {
             Name    = b.Name,
             Surname = b.Surname,
             Age     = a.AvgAge
         }
                                                                                                                                                 ).ToList(); secGrid.ItemsSource = result3;
     }
 }