partial void DeleteMailServers(MailServers instance);
partial void InsertMailServers(MailServers instance);
partial void UpdateMailServers(MailServers instance);
private void Save_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.Host.Text)) this.errorProvider.SetError(this.Host, "Le champ Hôte doit être complété."); else if (this.ValidateChildren()) { using (SelfMailerDataContext context = new SelfMailerDataContext()) { using (TransactionScope transaction = new TransactionScope()) { MailServers newMailServer; Senders newSender; if (this.ConfigList.SelectedIndex >= 0) { ComboBoxItem selected = this.ConfigList.SelectedItem as ComboBoxItem; newMailServer = context.MailServers.Single<MailServers>(x => x.ID == selected.MailServerKey); newSender = context.Senders.Single<Senders>(x => x.ID == selected.SenderKey); } else { newMailServer = context.MailServers.SingleOrDefault<MailServers>(x => x.Host == this.Host.Text && x.Username == this.Username.Text && x.Password_Value == this.Password.Text); if (newMailServer == null) { newMailServer = new MailServers(); context.MailServers.InsertOnSubmit(newMailServer); } newSender = context.Senders.SingleOrDefault<Senders>(x => x.Name == this.FromName.Text && x.Email == this.FromEmail.Text); if (newSender == null) { newSender = new Senders(); context.Senders.InsertOnSubmit(newSender); } } newMailServer.Host = this.Host.Text; newMailServer.Username = this.Username.Text; newMailServer.Password_Value = this.Password.Text; newMailServer.Password_AllowSave = true; newSender.Name = this.FromName.Text; newSender.Email = this.FromEmail.Text; context.SubmitChanges(); MailServerSender rel = context.MailServerSender.SingleOrDefault<MailServerSender>(x => x.MailServer_ID == newMailServer.ID && x.Sender_ID == newSender.ID); if (rel == null) { rel = new MailServerSender(); rel.MailServer_ID = newMailServer.ID; rel.Sender_ID = newSender.ID; context.MailServerSender.InsertOnSubmit(rel); } context.SubmitChanges(); transaction.Complete(); } } } MessageBox.Show("La configuration a été enregistrée."); this.LoadConfigurations(); }