private void editBtn_Click(object sender, EventArgs e) { int row = dataGridView1.CurrentCell.RowIndex; int id = Convert.ToInt32(dataGridView1[0, row].Value); try { var user = DirectoryDB.UsersInfoSet.Find(id); if (user.Access_level == "Owner") { MessageBox.Show("You can`t edit yourself", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if ((user.Access_level == "Admin" || user.Access_level == "User") && accessComboBox.SelectedIndex == 0) { MessageBox.Show("You can`t promote user to owner", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { user.Access_level = accessComboBox.Text; DirectoryDB.Entry(user).State = EntityState.Modified; DirectoryDB.SaveChanges(); MessageBox.Show("Done", "Action", MessageBoxButtons.OK, MessageBoxIcon.Information); DirectoryDB.UsersInfoSet.Load(); dataGridView1.DataSource = DirectoryDB.UsersInfoSet.Local.ToList(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void addBtn_Click(object sender, EventArgs e) { try { switch (activetable) { case "Subscribers": { var sub = DirectoryDB.SubscribersInfoSet.Find(currentId); sub.PassportData = propTextBox1.Text; sub.FullName = propTextBox2.Text; sub.Address = propTextBox3.Text; DirectoryDB.Entry(sub).State = EntityState.Modified; break; } case "Operators": { var ops = DirectoryDB.OperatorsInfoSet.Find(currentId); ops.Name = propTextBox1.Text; ops.Code = propTextBox2.Text; ops.AmountOfUsers = Convert.ToInt32(propTextBox3.Text); DirectoryDB.Entry(ops).State = EntityState.Modified; break; } case "Connections": { var con = DirectoryDB.ConnectionsInfoSet.Find(currentId); con.PhoneNumber = propTextBox1.Text; con.Arrear = Convert.ToInt32(propTextBox2.Text); con.Tariff = propTextBox3.Text; con.InstallationDate = Convert.ToDateTime(propTextBox4.Text); DirectoryDB.Entry(con).State = EntityState.Modified; break; } } DirectoryDB.SaveChanges(); MessageBox.Show("Done", "Action", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }