private async void btnGenerisi_Click(object sender, EventArgs e) { Action action = () => ucitajPodatke(); await Task.Run(() => { for (int i = 1; i <= brojTestova; i++) { Random rand = new Random(); Random rand2 = new Random(); var range = rand.Next(1, _db.Studenti.Count()); var randomStudent = new StudentiCovidTestovi() { DatumVrijeme = DateTime.Now, NalazDostavljen = rand.NextDouble() > 0.5, Rezultat = rand2.NextDouble() > 0.5 ? "Negativan" : "Pozitivan", Student = _db.Studenti.ToList().ElementAt(range) }; _db.StudentiCovidTestovi.Add(randomStudent); } }); _db.SaveChanges(); BeginInvoke(action); MessageBox.Show($"Uspjesno generisano {brojTestova} rezultata COVID testiranja."); }
private void btnDodaj_Click(object sender, EventArgs e) { if (provjeriDatum()) { var studentCovid = new StudentiCovidTestovi() { Student = cmbStudent.SelectedItem as Student, DatumVrijeme = dtmDatumTestiranja.Value, Rezultat = cmbRezultatTesta.SelectedItem.ToString(), NalazDostavljen = cbNalaz.Checked }; _db.StudentiCovidTestovi.Add(studentCovid); _db.SaveChanges(); ucitajPodatke(); } else { MessageBox.Show("Vec je unesen Student sa tim datumom", "Warning"); } }