private void Button1_Click(object sender, EventArgs e) { string name = cmbPackets.SelectedItem.ToString(); foreach (string nameServices in listServices.CheckedItems) { int idservice = _context.Services.First(s => s.ServiceNames == nameServices).Id; int id = _context.Packets.FirstOrDefault(p => p.PacketName == name).Id; PacketToServy packetToServy = new PacketToServy(); packetToServy.PacketsId = id; packetToServy.ServiceId = idservice; _context.PacketToServies.Add(packetToServy); } //string nameservice = listServices.SelectedItems.ToString(); _context.SaveChanges(); FillDataGrid(); }
private void Button2_Click(object sender, EventArgs e) { string name = cmbPackets.Text; int id = _context.Packets.FirstOrDefault(p => p.PacketName == name).Id; foreach (string nameServices in listServices.CheckedItems) { int idservice = _context.Services.First(s => s.ServiceNames == nameServices).Id; PacketToServy selectedService = _context.PacketToServies.FirstOrDefault(pts => pts.PacketsId == id && pts.ServiceId == idservice); _context.PacketToServies.Remove(selectedService); } ; _context.SaveChanges(); FillDataGrid(); }