/// <summary> /// Save the address to the database. Note that RecievedMail entities are saved as they are created /// and removed by their correponding methods. This method only saves the address itself - names /// and email. /// </summary> public void Save() { if (Address.FirstName == "") { throw new ArgumentException("First name must not be empty"); } if (Address.Email == "") { throw new ArgumentException("Email address must not be empty"); } try { new MailAddress(Address.Email, Address.FirstName); } catch (Exception) { throw new ArgumentException("Email address is not in a valid format."); } using (var db = new MailerEntities()) { db.Addresses.Attach(Address); db.Entry(Address).State = EntityState.Modified; db.SaveChanges(); } }
public void Save() { using (var db = new MailerEntities()) { db.MailingLists.Attach(MailingList); db.Entry(MailingList).State = EntityState.Modified; db.SaveChanges(); } }