public void CreateClient(Client newClient) { using (var model = new safricomEntities()) { var thisClient = new client(); createClientBasicInformation(newClient, model, thisClient, PersistanceMethod.Create); var clientId = thisClient.Id; var installationAddress = new clientaddress(); createInstallationAddress(newClient, clientId, model, installationAddress, PersistanceMethod.Create); var physicalAddress = new clientaddress(); createPhysicalAddress(newClient, model, clientId, physicalAddress, PersistanceMethod.Create); var postalAddress = new clientaddress(); createPostalAddress(newClient, clientId, model, postalAddress, PersistanceMethod.Create); } }
private void createPostalAddress(Client newClient, int clientId, safricomEntities model, clientaddress postalAddress, PersistanceMethod method) { postalAddress.street_number = newClient.PostalAddress.StreetNumber; postalAddress.street = newClient.PostalAddress.Street; postalAddress.post_box = newClient.PostalAddress.PoBox; postalAddress.city = newClient.PostalAddress.City; postalAddress.suburb = newClient.PostalAddress.Suburb; postalAddress.postal_code = newClient.PostalAddress.PostalCode; postalAddress.client_id = clientId; postalAddress.type = AddressType.Postal.ToString(); if (method == PersistanceMethod.Create) { model.clientaddresses.Add(postalAddress); } if (model.SaveChanges() > 0) { _log.Debug(String.Format("Successfully created client postal address of '{0} {1}'", newClient.Name, newClient.Surname)); } else { _log.Warn(String.Format("No changes were made for client postal address of '{0} {1}'", newClient.Name, newClient.Surname)); } }
private void createInstallationAddress(Client newClient, int clientId, safricomEntities model, clientaddress installationAddress, PersistanceMethod method) { installationAddress.street_number = newClient.InstallationAddress.StreetNumber; installationAddress.street = newClient.InstallationAddress.Street; installationAddress.city = newClient.InstallationAddress.City; installationAddress.suburb = newClient.InstallationAddress.Suburb; installationAddress.gps_coordinates = newClient.InstallationAddress.GPS; installationAddress.client_id = clientId; installationAddress.type = AddressType.Installation.ToString(); if (method == PersistanceMethod.Create) { model.clientaddresses.Add(installationAddress); } if (model.SaveChanges() > 0) { _log.Debug(String.Format("Successfully created client innstallation address of '{0} {1}'", newClient.Name, newClient.Surname)); } else { _log.Warn(String.Format("No changes were made for client installation address of '{0} {1}'", newClient.Name, newClient.Surname)); } }