private void Button_Click(object sender, RoutedEventArgs e) { if (ConnectionList.SelectedItem != null) { dynamic data = ConnectionList.SelectedItem; int id = data.ID; using (var context = new DatabasesContext()) { var remove = context.Db.SingleOrDefault(q => q.DatabaseID == id); context.Db.Remove(remove); context.SaveChanges(); } using (var context = new DatabasesContext()) { var connections = context.Db .Select(q => new { ID = q.DatabaseID, Address = q.Server_address, Login = q.Login, Password = q.Password, Port = q.Port }) .ToList(); databaseEntries.Clear(); foreach (var item in connections) { databaseEntries.Add(item); } } } }
/// <summary> /// Metoda ktora edytuje dany rekord i zamyka okno edytowania. /// </summary> private void Button_Click(object sender, RoutedEventArgs e) { using var context = new DatabasesContext(); var update = context.Db.SingleOrDefault(q => q.DatabaseID == id_db); string encrypt_pass = PasswordHash.Encrypt(password.Text); update.Server_address = server_address.Text; update.Login = login.Text; update.Password = encrypt_pass; update.Port = port.Text; context.SaveChanges(); this.Close(); }
/// <summary> /// metoda ktora dodaje baze /// </summary> private void AddDatabase() { string pass_hash = PasswordHash.Encrypt(Password.Password); var db = new Database { Server_address = Server_address.Text, Login = Login.Text, Password = pass_hash, Port = Port.Text }; using (var context = new DatabasesContext()) { context.Db.Add(db); context.SaveChanges(); } Close(); }