public PersonViewModel() { PersonCommands = new PersonCommands(); using (WorkDbContext db = new WorkDbContext()) { Persons = new ObservableCollection <Person>(); foreach (var person in db.Persons) { Persons.Add(person); } Departments = new List <Department>(); foreach (var department in db.Departments) { Departments.Add(department); } } PersonCollectionView = CollectionViewSource.GetDefaultView(Persons); TemporarySelectedPerson = new Person(); if (Application.Current.MainWindow != null) { int id = (Application.Current.MainWindow.DataContext as MainViewModel)?.NavigationId ?? 0; PersonCollectionView.MoveCurrentTo(Persons.FirstOrDefault(x => x.Id == id)); } }
private Person CreatePerson(string firstName = null, string lastName = null, DateTime?bDate = null) { return(PersonCommands.SavePerson(new Person { FirstName = firstName ?? RandomUtil.GetRandomString(), LastName = lastName ?? RandomUtil.GetRandomString(), BirthDate = bDate ?? RandomUtil.GetRandomDateInThePast(1) }, Context)); }
public override void SaveEntity_EntityIsNew_EntityIsCreated() { var person = PersonCommands.SavePerson(new Person { FirstName = RandomUtil.GetRandomString(), LastName = RandomUtil.GetRandomString() }, Context); var title = TitleCommands.SaveTitle(new Title { Description = RandomUtil.GetRandomString() }, Context); var personTitle = PersonTitleCommands.SavePersonTitle(new PersonTitle { IdPerson = person.IdPerson, IdTitle = title.IdTitle }, Context); Assert.IsNotNull(personTitle); }
private void BtnZapiszPerson_Click(object sender, EventArgs e) { PersonCommands myConnd = new PersonCommands(IniDataBaseFile.conPath, IniDataBaseFile.conFile); // //string s = "select * from osoba where osobaid=1"; //var pp = myConnd.SqlReturnOneRecord(s); //PersonValidate person = new PersonValidate(pp.ImieNazwisko,pp.KodMiasto,pp.ulicaNr,pp.Telefon,pp.Email); p = new PersonValidate(txtImieNazwisko.Text, txtKodMiasto.Text, txtUlicaNr.Text, txtTelefon.Text, txtEmail.Text); string personExists = "select count(*) from osoba " + "where ImieNazwisko = " + "\"" + txtImieNazwisko.Text + "\"" + " and KodMiasto = " + "\"" + txtKodMiasto.Text + "\"" + "and ulicaNr = " + "\"" + txtUlicaNr.Text + "\""; string personCount = myConnd.SqlReturnOneValue(personExists); if (PersonValidate.PersonIsOk) { if (personCount != "0") { MessageBox.Show("istnieje już w bazie osoba:\n\n" + p.ImieNazwisko + ",\n" + p.KodMiasto + ",\n" + p.ulicaNr); } else { DialogResult dialogResult = MessageBox.Show("Czy zapisać osobę?", "ZAPIS OSOBY", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { myConnd.SqlInsertOsoba(txtImieNazwisko.Text, txtKodMiasto.Text, txtUlicaNr.Text, txtTelefon.Text, txtEmail.Text); txtImieNazwisko.Text = ""; txtKodMiasto.Text = ""; txtUlicaNr.Text = ""; txtTelefon.Text = ""; txtEmail.Text = ""; } else if (dialogResult == DialogResult.No) { this.Close(); } } } else { MessageBox.Show("Błędnie wypełnione informacje!!!"); } }
public static PersonTitle CreatePersonTitle(FootBallContext context, out Person person, out Title title) { person = PersonCommands.SavePerson( new Person { FirstName = RandomUtil.GetRandomString(), LastName = RandomUtil.GetRandomString() }, context); Assert.IsNotNull(person); title = TitleCommands.SaveTitle(new Title { Description = RandomUtil.GetRandomString() }, context); Assert.IsNotNull(title); return(PersonTitleCommands.SavePersonTitle(new PersonTitle { IdPerson = person.IdPerson, IdTitle = title.IdTitle }, context)); }