예제 #1
0
        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));
            }
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
 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);
     }
 }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
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);
            }
        }
예제 #9
0
        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));
            }
        }