private void createClientBasicInformation(Client newClient, safricomEntities model, client thisClient, PersistanceMethod method) { thisClient.name = newClient.Name; thisClient.surname = newClient.Surname; thisClient.business_name = newClient.BusinessName; thisClient.cell_phone_one = newClient.CellPhoneOne; thisClient.email = newClient.Email; thisClient.telephone_work = newClient.Telephone; thisClient.id_passport = newClient.IdPassport; thisClient.vat_registration = newClient.VatNumber; if (method == PersistanceMethod.Create) { model.clients.Add(thisClient); } if (model.SaveChanges() > 0) { _log.Debug(String.Format("Successfully created client basic information form '{0} {1}'", thisClient.name, thisClient.surname)); } else { _log.Warn(String.Format("No changes were made for client basic information of '{0} {1}'", thisClient.name, thisClient.surname)); } }
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 client updateClientBasicInformation(Client newClient, safricomEntities model) { var thisClient = (from clt in model.clients where clt.name == newClient.Name && clt.surname == newClient.Surname && clt.id_passport == newClient.IdPassport select clt).FirstOrDefault(); createClientBasicInformation(newClient, model, thisClient, PersistanceMethod.Update); return(thisClient); }
public void UpdateClient(Client newClient) { using (var model = new safricomEntities()) { var thisClient = updateClientBasicInformation(newClient, model); var clientId = thisClient.Id; updateInstallationAddress(newClient, model, clientId); updatePhysicalAddress(newClient, model, clientId); updatePostalAddress(newClient, model, clientId); } }
private void updateInstallationAddress(Client newClient, safricomEntities model, int clientId) { var installationAddress = (from add in model.clientaddresses where add.client_id == clientId && add.type == "Installation" select add).FirstOrDefault(); if (installationAddress != null) { createInstallationAddress(newClient, clientId, model, installationAddress, PersistanceMethod.Update); } }
private void updatePhysicalAddress(Client newClient, safricomEntities model, int clientId) { var physicalAddress = (from add in model.clientaddresses where add.client_id == clientId && add.type == "Physical" select add).FirstOrDefault(); if (physicalAddress != null) { createPhysicalAddress(newClient, model, clientId, physicalAddress, PersistanceMethod.Update); } }
public bool CheckIfClientExists(Client client) { using (var model = new safricomEntities()) { var clients = (from clt in model.clients where clt.name == client.Name && clt.surname == client.Surname && clt.id_passport == client.IdPassport select clt).ToList(); return(clients.Count > 0); } }
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 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)); } }