public void DeletePartyContact(int partyId, int contactId) { try { using (PartyEntities context = new PartyEntities(this.connectionString)) { PartyContact partyContact = (from pc in context.PartyContacts where (pc.PartyId == partyId && pc.ContactId == contactId) select pc).First(); if (partyContact != null) { context.DeleteObject(partyContact); context.SaveChanges(); } } } catch (Exception ex) { if (ex is UpdateException) { throw ex.InnerException; } throw; } }
public void UpdatePartyContact(int partyId, int contactId, DateTime validFrom, DateTime validUntil) { try { using (PartyEntities context = new PartyEntities(this.connectionString)) { PartyContact partyContact = (PartyContact) (from pc in context.PartyContacts where (pc.PartyId == partyId && pc.ContactId == contactId) select pc).First(); if (partyContact != null) { partyContact.ValidFrom = validFrom; partyContact.ValidUntil = validUntil; context.SaveChanges(); } } } catch (Exception ex) { if (ex is UpdateException) { throw ex.InnerException; } throw; } }
public void CreatePartyContact(int partyId, int contactId, DateTime validFrom, DateTime validUntil) { try { using (PartyEntities context = new PartyEntities(this.connectionString)) { PartyContact partyContact = new PartyContact(); partyContact.PartyId = partyId; partyContact.ContactId = contactId; partyContact.ValidFrom = validFrom; partyContact.ValidUntil = validUntil; context.PartyContacts.AddObject(partyContact); context.SaveChanges(); } } catch (Exception ex) { if (ex is UpdateException) { throw ex.InnerException; } throw; } }
public Acknowledgement DeletePartyContact(string partyIdStr, string contactIdStr) { try { int partyId, contactId; if (!int.TryParse(partyIdStr, out partyId)) { throw (new WebFaultException <Error>( new Error(string.Format("'{0}' is not a valid party identifier", partyIdStr)), HttpStatusCode.OK)); } if (!int.TryParse(contactIdStr, out contactId)) { throw (new WebFaultException <Error>( new Error(string.Format("'{0}' is not a valid contact identifier", contactIdStr)), HttpStatusCode.OK)); } PartyContact pc = database.GetPartyContact(partyId, contactId); if (pc == null) { throw (new WebFaultException <Error>( new Error(string.Format("Party {0} is not linked to contact {1}", partyId, contactId)), HttpStatusCode.OK)); } database.DeletePartyContact(partyId, contactId); return(new Acknowledgement( string.Format("Contact {0} removed from party {1}", contactId, partyId))); } catch (Exception ex) { throw MakeWebFaultException(ex); } }
public PartyContact UpdatePartyContact(string partyIdStr, string contactIdStr, PartyContact partyContact) { try { int partyId, contactId; if (!int.TryParse(partyIdStr, out partyId)) { throw (new WebFaultException <Error>( new Error(string.Format("'{0}' is not a valid party identifier", partyIdStr)), HttpStatusCode.OK)); } if (!int.TryParse(contactIdStr, out contactId)) { throw (new WebFaultException <Error>( new Error(string.Format("'{0}' is not a valid contact identifier", contactIdStr)), HttpStatusCode.OK)); } PartyContact pc = database.GetPartyContact(partyId, contactId); if (pc == null) { database.CreatePartyContact(partyId, contactId, partyContact.ValidFrom, partyContact.ValidUntil); } else { database.UpdatePartyContact(partyId, contactId, partyContact.ValidFrom, partyContact.ValidUntil); } return(GetPartyContact(partyIdStr, contactIdStr)); } catch (Exception ex) { throw MakeWebFaultException(ex); } }
public PartyContact UpdatePartyContact(string partyIdStr, string contactIdStr, PartyContact partyContact) { try { int partyId, contactId; if (!int.TryParse(partyIdStr, out partyId)) { throw (new WebFaultException<Error>( new Error(string.Format("'{0}' is not a valid party identifier", partyIdStr)), HttpStatusCode.OK)); } if (!int.TryParse(contactIdStr, out contactId)) { throw (new WebFaultException<Error>( new Error(string.Format("'{0}' is not a valid contact identifier", contactIdStr)), HttpStatusCode.OK)); } PartyContact pc = database.GetPartyContact(partyId, contactId); if (pc == null) { database.CreatePartyContact(partyId, contactId, partyContact.ValidFrom, partyContact.ValidUntil); } else { database.UpdatePartyContact(partyId, contactId, partyContact.ValidFrom, partyContact.ValidUntil); } return GetPartyContact(partyIdStr, contactIdStr); } catch (Exception ex) { throw MakeWebFaultException(ex); } }