private void ButtonAddEditEmployee_Click(object sender, RoutedEventArgs e) { if (this.add_edit == true) { if (textBlockAddEditaddress.Text != string.Empty && textBlockAddEditbirth_date.Text != string.Empty && textBlockAddEditfname.Text != string.Empty && textBlockAddEditlName.Text != string.Empty && textBlockAddEditlogin.Text != string.Empty && textBlockAddEditname.Text != string.Empty && textBlockAddEditpassword.Text != string.Empty && textBlockAddEditphone.Text != string.Empty && textBlockAddEditposition.Text != string.Empty && textBlockAddEditposition_set_date.Text != string.Empty && textBlockAddEditshop.Text != string.Empty) { WpfApplicationEntity.API.Employee objectEmployee = new WpfApplicationEntity.API.Employee(); objectEmployee.address = textBlockAddEditaddress.Text; objectEmployee.birth_date = textBlockAddEditbirth_date.Text; objectEmployee.fName = textBlockAddEditfname.Text; objectEmployee.lName = textBlockAddEditlName.Text; objectEmployee.login = textBlockAddEditlogin.Text; objectEmployee.name = textBlockAddEditname.Text; objectEmployee.password = textBlockAddEditpassword.Text; objectEmployee.phone = textBlockAddEditphone.Text; objectEmployee.position = textBlockAddEditposition.Text; objectEmployee.position_set_date = textBlockAddEditposition_set_date.Text; // objectEmployee.shop = (ICollection<API.Shop>)textBlockAddEditshop.Text; try { using (WpfApplicationEntity.API.MyDBContext objectMyDBContext = new WpfApplicationEntity.API.MyDBContext()) { objectMyDBContext.Employees.Add(objectEmployee); objectMyDBContext.SaveChanges(); } MessageBox.Show("Сотрудник добавлен"); this.DialogResult = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Заполните все поля!", "Ошибка!"); this.DialogResult = false; } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { using (WpfApplicationEntity.API.MyDBContext objectMyDBContext = new WpfApplicationEntity.API.MyDBContext()) { if (objectMyDBContext.Database.Exists() == false) { objectMyDBContext.Database.Create(); WpfApplicationEntity.API.Employee objectEmployee = new WpfApplicationEntity.API.Employee(); objectEmployee.fName = "user fname"; objectEmployee.name = "user"; objectEmployee.lName = "user"; objectEmployee.position = "admin"; objectEmployee.login = "******"; objectEmployee.password = "******"; objectEmployee.birth_date = "555555"; objectEmployee.address = "home"; objectEmployee.phone = "543543"; objectEmployee.position_set_date = "234556"; objectMyDBContext.Employees.Add(objectEmployee); objectMyDBContext.SaveChanges(); } //WpfApplicationEntity.API.Employee objectEmployee1 = new WpfApplicationEntity.API.Employee(); //objectEmployee1.fName = "user fname"; //objectEmployee1.name = "user"; //objectEmployee1.lName = "user"; //objectEmployee1.position = "admin"; //objectEmployee1.login = "******"; //objectEmployee1.password = "******"; //objectEmployee1.birth_date = "555555"; //objectEmployee1.address = "home"; //objectEmployee1.phone = "543543"; //objectEmployee1.position_set_date = "234556"; //objectMyDBContext.Employees.Add(objectEmployee1); //objectMyDBContext.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } this.ShowAll(); }