/// <summary>
 /// Créez un nouvel objet Sender.
 /// </summary>
 /// <param name="id">Valeur initiale de la propriété ID.</param>
 /// <param name="name">Valeur initiale de la propriété Name.</param>
 /// <param name="email">Valeur initiale de la propriété Email.</param>
 public static Sender CreateSender(global::System.Int32 id, global::System.String name, global::System.String email)
 {
     Sender sender = new Sender();
     sender.ID = id;
     sender.Name = name;
     sender.Email = email;
     return sender;
 }
        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 Senders. Utilisez la méthode .Add de la propriété ObjectSet&lt;T&gt; associée à la place.
 /// </summary>
 public void AddToSenders(Sender sender)
 {
     base.AddObject("Senders", sender);
 }