public Email CreateEmail(Email email) { try { int newId = database.CreateEmail(email.SubType, email.Address); return (Email)GetContact(Convert.ToString(newId)); } catch (Exception ex) { throw MakeWebFaultException(ex); } }
public int CreateEmail(string type, string address) { try { using (PartyEntities context = new PartyEntities(this.connectionString)) { Email email = new Email(); email.Address = address; email.SubType = type; email.Type = "E"; context.Contacts.AddObject(email); context.SaveChanges(); return email.Id; } } catch (Exception ex) { if (ex is UpdateException) { throw ex.InnerException; } throw; } }
public Email UpdateEmail(string idStr, Email email) { try { int id; if (!int.TryParse(idStr, out id)) { throw (new WebFaultException<Error>( new Error(string.Format("'{0}' is not a valid contact identifier", idStr)), HttpStatusCode.OK)); } if (database.GetContact(id) == null) { throw (new WebFaultException<Error>( new Error(string.Format("Email {0} not found", id)), HttpStatusCode.OK)); } database.UpdateEmail(id, email.SubType, email.Address); return (Email)GetContact(idStr); } catch (Exception ex) { throw MakeWebFaultException(ex); } }