Exemplo n.º 1
0
        private static ICompanyContactPerson CreateCompanyContactPerson(IDalSession session,
                                                        IContactCompany company,
                                                        string BurgerServiceNummer,
                                                        string Voorletters,
                                                        string Tussenvoegsels,
                                                        string Naam,
                                                        Address PostalAddress,
                                                        Address ResidentialAddress,
                                                        IContactDetails ContactDetails,
                                                        Gender ContactGender,
                                                        INationality ContactNationality,
                                                        IIdentification Id,
                                                        DateTime Dob,
                                                        IManagementCompany AssetManager,
                                                        DateTime creationdate)
        {
            ICompanyContactPerson cmpcp = null;
            IContactPerson contact = null;

            if (company != null && !string.IsNullOrEmpty(Naam))
            {
                if (!LookupContactPersonByBSN(session, BurgerServiceNummer, out contact))
                {
                    contact = new ContactPerson(Voorletters,
                                                    Tussenvoegsels,
                                                    ContactGender,
                                                    ContactNationality,
                                                    Naam,
                                                    PostalAddress,
                                                    ResidentialAddress,
                                                    ContactDetails);
                    contact.BurgerServiceNummer = BurgerServiceNummer;
                    contact.AssetManager = (IAssetManager)AssetManager;
                    contact.Identification = Id;
                    contact.DateOfBirth = Dob;
                    contact.CreationDate = creationdate;
                }
                cmpcp = new CompanyContactPerson(contact, company);
            }
            return cmpcp;
        }
Exemplo n.º 2
0
        public static void SavePerson(ref int persID, ref bool blnSaveSuccess, PersonDetails persDetails)
        {
            if (!SecurityManager.IsCurrentUserInRole("Data Mtce: Account Edit"))
                throw new System.Security.SecurityException("You are not authorized to update contact details.");

            IDalSession session = NHSessionFactory.CreateSession();

            try
            {
                IContactPerson person = null;
                Address postalAddress = null;
                Address residentialAddress = null;
                IContactsNAW newNaw = null;
                IContactsNAW currentNaw = null;
                IContactsIntroducer currentIntroducer = null;
                IContactsIntroducer newIntroducer = null;

                bool boolNawInsert = true;
                IManagementCompany company = LoginMapper.GetCurrentManagmentCompany(session);
                bool loggedInAsStichting = company.IsStichting;

                if (persID != 0)
                {
                    person = GetContact(session, persID);
                    currentNaw = person.CurrentNAW;
                    currentIntroducer = person.CurrentIntroducer;
                }
                else
                {
                    person = new ContactPerson();
                    currentNaw = new ContactsNAW();
                }

                // check if bsn does not already exists
                long bsnEntries = session.Session.GetNamedQuery(
                    "B4F.TotalGiro.CRM.Contact.CheckBSNIsUnique")
                    .SetParameter("personId", persID)
                    .SetParameter("companyId", (person.AssetManager != null ? person.AssetManager.Key : company.Key))
                    .SetParameter("bsn", persDetails.BurgerServiceNummer)
                    .UniqueResult<long>();
                if (bsnEntries > 0)
                    throw new ApplicationException("It is not possible to enter this person since the bsn already exists");

                person.IsActive = Convert.ToBoolean(persDetails.IsActive);
                person.HasMinimumData = persDetails.HasMinimumData;

                if (person.Identification == null)
                    person.Identification = new Identification();
                if (person.Identification.IdentificationType == null)
                    person.Identification.IdentificationType = new IdentificationType();
                if (person.ContactDetails == null)
                    person.ContactDetails = new ContactDetails();
                if (person.ContactDetails.Fax == null)
                    person.ContactDetails.Fax = new TelephoneNumber();
                if (person.ContactDetails.Telephone == null)
                    person.ContactDetails.Telephone = new TelephoneNumber();
                if (person.ContactDetails.Mobile == null)
                    person.ContactDetails.Mobile = new TelephoneNumber();
                if (person.ContactDetails.TelephoneAH == null)
                    person.ContactDetails.TelephoneAH = new TelephoneNumber();

                if (persDetails.Introducer != null && persDetails.Introducer.Length > 0 && Convert.ToInt32(persDetails.Introducer) != int.MinValue)
                {
                    newIntroducer = new ContactsIntroducer();
                    newIntroducer.Remisier = RemisierMapper.GetRemisier(session, Convert.ToInt32(persDetails.Introducer));
                    newIntroducer.RemisierEmployee = RemisierEmployeeMapper.GetRemisierEmployee(session, Convert.ToInt32(persDetails.IntroducerEmployee));
                }

                if (persDetails.InternetEnabled.Length > 0)
                {
                    if (persDetails.InternetEnabled.Equals(InternetEnabled.No.ToString()))
                        person.InternetEnabled = InternetEnabled.No;
                    else if (persDetails.InternetEnabled.Equals(InternetEnabled.Yes.ToString()))
                        person.InternetEnabled = InternetEnabled.Yes;
                    else
                        person.InternetEnabled = InternetEnabled.Unknown;
                }
                else
                    person.InternetEnabled = InternetEnabled.Unknown;

                if (int.Parse(persDetails.IDType) != int.MinValue)
                {
                    person.Identification.Number = persDetails.IDNumber;

                    if (persDetails.IDExpirationDate.Length > 0)
                    {
                        person.Identification.ValidityPeriod = Convert.ToDateTime(persDetails.IDExpirationDate);
                    }
                    else
                    {
                        person.Identification.ValidityPeriod = DateTime.MinValue;
                    }
                    person.Identification.IdentificationType.Key = Convert.ToInt32(persDetails.IDType);
                }
                else
                    person.Identification = null;

                person.ContactDetails.SendNewsItem = persDetails.SendNewsItem;
                person.ContactDetails.Email = persDetails.Email;
                person.ContactDetails.Mobile.Number = persDetails.Mobile;
                person.ContactDetails.Telephone.Number = persDetails.Telephone;
                person.ContactDetails.TelephoneAH.Number = persDetails.TelephoneAH;
                person.ContactDetails.Fax.Number = persDetails.Fax;

                if (persDetails.Street.Length > 0 || persDetails.HouseNumber.Length > 0 ||
                    persDetails.HouseNumberSuffix.Length > 0 || persDetails.Postalcode.Length > 0 ||
                    persDetails.City.Length > 0)
                {
                    residentialAddress = new Address();
                    residentialAddress.Street = persDetails.Street;
                    residentialAddress.HouseNumber = persDetails.HouseNumber;
                    residentialAddress.HouseNumberSuffix = persDetails.HouseNumberSuffix;
                    residentialAddress.PostalCode = persDetails.Postalcode;
                    residentialAddress.City = persDetails.City;
                    if (int.Parse(persDetails.Country) != int.MinValue)
                        residentialAddress.Country = CountryMapper.GetCountry(session, Convert.ToInt32(persDetails.Country));
                    else
                        residentialAddress.Country = null;
                }

                if (persDetails.PostalStreet.Length > 0 || persDetails.PostalHouseNumber.Length > 0 ||
                    persDetails.PostalHouseNumberSuffix.Length > 0 || persDetails.PostalPostalcode.Length > 0 ||
                    persDetails.PostalCity.Length > 0)
                {
                    postalAddress = new Address();
                    postalAddress.Street = persDetails.PostalStreet;
                    postalAddress.HouseNumber = persDetails.PostalHouseNumber;
                    postalAddress.HouseNumberSuffix = persDetails.PostalHouseNumberSuffix;
                    postalAddress.PostalCode = persDetails.PostalPostalcode;
                    postalAddress.City = persDetails.PostalCity;
                    if (int.Parse(persDetails.PostalCountry) != int.MinValue)
                        postalAddress.Country = CountryMapper.GetCountry(session, Convert.ToInt32(persDetails.PostalCountry));
                    else
                        postalAddress.Country = null;
                }

                if (residentialAddress != null && postalAddress == null)
                    postalAddress = residentialAddress;
                else if (residentialAddress == null && postalAddress != null)
                    residentialAddress = postalAddress;

                newNaw = new ContactsNAW(persDetails.LastName, postalAddress, residentialAddress);

                if (currentNaw.Name == null || (currentNaw != null && !currentNaw.Name.Equals(newNaw.Name)))
                    boolNawInsert = true;
                // Then compare addresses
                else if (currentNaw.Name.Equals(newNaw.Name) && residentialAddress != null)
                {
                    if (currentNaw.ResidentialAddress != null)
                    {
                        // If addresses the same: no need for an insert
                        if (newNaw.Equals(currentNaw))
                            boolNawInsert = false;
                    }
                    else
                        boolNawInsert = true;
                }
                else
                {
                    newNaw = new ContactsNAW();
                    newNaw.Name = persDetails.LastName;
                    boolNawInsert = true;
                }

                if (boolNawInsert)
                {
                    person.ContactsNAWs.Add(newNaw);
                    person.CurrentNAW = newNaw;
                }

                if (currentIntroducer != null || newIntroducer != null)
                {
                    if (!(currentIntroducer != null && newIntroducer != null &&
                            newIntroducer.Equals(currentIntroducer)))
                    {
                        person.ContactsIntroducers.Add(newIntroducer);
                        person.CurrentIntroducer = newIntroducer;
                    }
                }

                person.Title = persDetails.Title;
                person.FirstName = persDetails.Initials;
                person.MiddleName = persDetails.MiddleName;
                if (persDetails.Gender.Length > 0)
                    person.Gender = (Convert.ToInt32(persDetails.Gender).Equals((int)Gender.Male) ? Gender.Male : Gender.Female);
                if (persDetails.ResidentialState.Length > 0)
                    person.ResidentialState = (Convert.ToInt32(persDetails.ResidentialState).Equals((int)ResidentStatus.Resident) ? ResidentStatus.Resident : ResidentStatus.NonResident);

                if (int.Parse(persDetails.Nationality) != int.MinValue)
                {
                    if (person.Nationality == null || person.Nationality.Key != int.Parse(persDetails.Nationality))
                        person.Nationality = NationalityMapper.GetNationality(session, Convert.ToInt32(persDetails.Nationality));
                }
                person.BurgerServiceNummer = persDetails.BurgerServiceNummer;

                if (persDetails.BirthDate.Length > 0)
                    person.DateOfBirth = Convert.ToDateTime(persDetails.BirthDate);
                else
                    person.DateOfBirth = DateTime.MinValue;

                if (person.CurrentNAW.Name.Length > 0 && person.FirstName.Length > 0 &&
                        Util.IsNotNullDate(person.DateOfBirth) &&
                        persDetails.Gender.Length > 0 &&
                        person.Nationality != null &&
                        (person.Identification != null &&
                          person.Identification.Number.Length > 0 &&
                          Util.IsNotNullDate(person.Identification.ValidityPeriod)) &&
                        person.BurgerServiceNummer.Length > 0 &&
                        person.InternetEnabled != InternetEnabled.Unknown &&
                        (person.ContactDetails != null &&
                           person.ContactDetails.Email.Length > 0 &&
                           person.ContactDetails.Telephone != null &&
                           person.ContactDetails.Telephone.Number.Length > 0) &&
                       residentialAddress != null &&
                       residentialAddress.Street.Length > 0 &&
                       residentialAddress.HouseNumber.Length > 0 &&
                       residentialAddress.PostalCode.Length > 0 &&
                       residentialAddress.City.Length > 0)
                {
                    person.StatusNAR = EnumStatusNAR.Complete;
                }
                else
                    person.StatusNAR = EnumStatusNAR.Incomplete;

                if (persID == 0 && !loggedInAsStichting)
                    person.AssetManager = (IAssetManager)company;
                if (persID == 0)
                    blnSaveSuccess = ContactMapper.Insert(session, person);
                else
                {
                    blnSaveSuccess = ContactMapper.Update(session, person);
                }

                persID = person.Key;
            }
            finally
            {
                session.Close();
            }
        }
Exemplo n.º 3
0
        private static IContactPerson CreateContactPerson(IDalSession session,
                                                        string BurgerServiceNummer,
                                                        string Voorletters,
                                                        string Tussenvoegsels,
                                                        string Naam,
                                                        Address PostalAddress,
                                                        Address ResidentialAddress,
                                                        IContactDetails ContactDetails,
                                                        Gender ContactGender,
                                                        INationality ContactNationality,
                                                        IIdentification Id,
                                                        DateTime Dob,
                                                        IManagementCompany AssetManager,
                                                        DateTime creationdate)
        {
            IContactPerson theContact = null;

            //1st see if the contact exists
            if (!LookupContactPersonByBSN(session, BurgerServiceNummer, out theContact))
            {
                if (!string.IsNullOrEmpty(Naam))
                {
                    theContact = new ContactPerson(Voorletters,
                                                    Tussenvoegsels,
                                                    ContactGender,
                                                    ContactNationality,
                                                    Naam,
                                                    PostalAddress,
                                                    ResidentialAddress,
                                                    ContactDetails);
                    theContact.BurgerServiceNummer = BurgerServiceNummer;
                    theContact.AssetManager = (IAssetManager)AssetManager;
                    theContact.Identification = Id;
                    theContact.DateOfBirth = Dob;
                    theContact.CreationDate = creationdate;
                }
            }
            return theContact;
        }