private async void Button3_Click(object sender, EventArgs e) { Package selectedPackage = (Package)comboBox1.SelectedItem; selectedPackage.Name = textBox1.Text.Trim(); Time selectedTime = (Time)comboBox2.SelectedItem; selectedPackage.Time = selectedTime; selectedPackage.Price__per_month_ = numericPrice.Value; foreach (var item in fitnessEntities.ServicesToPackages.Where(stp => stp.PackageId == selectedPackage.id).ToList()) { fitnessEntities.ServicesToPackages.Remove(item); } await fitnessEntities.SaveChangesAsync(); foreach (var item in flowLayoutPanel1.Controls) { CheckBox checkbox = (CheckBox)item; if (checkbox.Checked) { ServicesToPackage servicesToPackage = new ServicesToPackage(); servicesToPackage.PackageId = selectedPackage.id; servicesToPackage.ServiceId = (int)checkbox.Tag; fitnessEntities.ServicesToPackages.Add(servicesToPackage); } } await fitnessEntities.SaveChangesAsync(); MessageBox.Show("Seçilmiş paketin məlumatları yeniləndi"); textBox1.Text = ""; comboBox1.Items.Clear(); comboBox1.Items.AddRange(fitnessEntities.Packages.ToArray()); comboBox2.SelectedIndex = -1; numericPrice.Value = 0; foreach (var item in flowLayoutPanel1.Controls) { CheckBox checkbox = (CheckBox)item; checkbox.Checked = false; } }
private async void Button1_Click(object sender, EventArgs e) { string name = textBox1.Text.Trim(); Time time = (Time)comboBox2.SelectedItem; decimal price = numericPrice.Value; Package package = new Package(); package.Name = name; package.Time = time; package.Price__per_month_ = price; fitnessEntities.Packages.Add(package); await fitnessEntities.SaveChangesAsync(); foreach (var item in flowLayoutPanel1.Controls) { CheckBox checkbox = (CheckBox)item; if (checkbox.Checked) { ServicesToPackage servicesToPackage = new ServicesToPackage(); servicesToPackage.ServiceId = Convert.ToInt32(checkbox.Tag); servicesToPackage.PackageId = package.id; fitnessEntities.ServicesToPackages.Add(servicesToPackage); } } await fitnessEntities.SaveChangesAsync(); MessageBox.Show("Yeni paket əlavə olundu"); textBox1.Text = ""; comboBox1.Items.Clear(); comboBox1.Items.AddRange(fitnessEntities.Packages.ToArray()); comboBox2.SelectedIndex = -1; numericPrice.Value = 0; foreach (var item in flowLayoutPanel1.Controls) { CheckBox checkbox = (CheckBox)item; checkbox.Checked = false; } }