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 (var entities = new SelfMailerContainer())
                {
                    MailServer newMailServer;
                    Sender newSender;
                    if (this.ConfigList.SelectedIndex >= 0)
                    {
                        ComboBoxItem selected = this.ConfigList.SelectedItem as ComboBoxItem;
                        newMailServer = entities.GetObjectByKey(selected.MailServerKey) as MailServer;
                        newSender = entities.GetObjectByKey(selected.SenderKey) as Sender;
                    }
                    else
                    {
                        newMailServer = entities.MailServers.Where("it.Host = @Host && it.Username = @Username && it.Password.Value = @PasswordValue"
                            , new ObjectParameter("Host", this.Host.Text)
                            , new ObjectParameter("Username", this.Username.Text)
                            , new ObjectParameter("PasswordValue", this.Password.Text)).FirstOrDefault<MailServer>();
                        if (newMailServer == null)
                        {
                            newMailServer = new MailServer();
                            entities.AddToMailServers(newMailServer);
                        }

                        newSender = entities.Senders.Where("it.Name = @Name && it.Email = @Email"
                           , new ObjectParameter("Name", this.FromName.Text)
                           , new ObjectParameter("Email", this.FromEmail.Text)).FirstOrDefault<Sender>();
                        if (newSender == null)
                        {
                            newSender = new Sender();
                            entities.AddToSenders(newSender);
                        }

                        if (!newSender.MailServer.Contains(newMailServer))
                        {
                            newSender.MailServer.Add(newMailServer);
                        }
                    }

                    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;

                    entities.SaveChanges();
                }
            }
            MessageBox.Show("La configuration a été enregistrée.");
            this.LoadConfigurations();
        }
 /// <summary>
 /// Méthode déconseillée pour ajouter un nouvel objet à l'EntitySet MailServers. Utilisez la méthode .Add de la propriété ObjectSet&lt;T&gt; associée à la place.
 /// </summary>
 public void AddToMailServers(MailServer mailServer)
 {
     base.AddObject("MailServers", mailServer);
 }
 /// <summary>
 /// Créez un nouvel objet MailServer.
 /// </summary>
 /// <param name="id">Valeur initiale de la propriété ID.</param>
 /// <param name="host">Valeur initiale de la propriété Host.</param>
 /// <param name="username">Valeur initiale de la propriété Username.</param>
 /// <param name="password">Valeur initiale de la propriété Password.</param>
 public static MailServer CreateMailServer(global::System.Int32 id, global::System.String host, global::System.String username, Password password)
 {
     MailServer mailServer = new MailServer();
     mailServer.ID = id;
     mailServer.Host = host;
     mailServer.Username = username;
     mailServer.Password = StructuralObject.VerifyComplexObjectIsNotNull(password, "Password");
     return mailServer;
 }
 /// <summary>
 /// Créez un nouvel objet MailServer.
 /// </summary>
 /// <param name="id">Valeur initiale de la propriété ID.</param>
 /// <param name="host">Valeur initiale de la propriété Host.</param>
 public static MailServer CreateMailServer(global::System.Int32 id, global::System.String host)
 {
     MailServer mailServer = new MailServer();
     mailServer.ID = id;
     mailServer.Host = host;
     return mailServer;
 }