Beispiel #1
0
        public static void SaveCompany(ref int compID, ref bool blnSave, CompanyDetails compDetails)
        {
            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
            {
                IContactCompany comp = null;
                Address postalAddress = null;
                Address residentialAddress = null;
                IContactsNAW newNaw = null;
                IContactsNAW currentNaw = null;
                IContactsIntroducer currentIntroducer = null;
                IContactsIntroducer newIntroducer = null;

                bool boolNawInsert = true;

                if (compID != 0)
                {
                    comp = GetContact(session, compID);
                    currentNaw = comp.CurrentNAW;
                    currentIntroducer = comp.CurrentIntroducer;
                }
                else
                {
                    comp = new ContactCompany();
                    currentNaw = new ContactsNAW();
                }

                comp.IsActive = Convert.ToBoolean(compDetails.IsActive);

                if (compDetails.DateOfFoundation.Length > 0)
                    comp.DateOfFounding = Convert.ToDateTime(compDetails.DateOfFoundation);
                else
                    comp.DateOfFounding = DateTime.MinValue;

                if (comp.ContactDetails == null)
                    comp.ContactDetails = new ContactDetails();
                if (comp.ContactDetails.Fax == null)
                    comp.ContactDetails.Fax = new TelephoneNumber();
                if (comp.ContactDetails.Telephone == null)
                    comp.ContactDetails.Telephone = new TelephoneNumber();
                if (comp.ContactDetails.Mobile == null)
                    comp.ContactDetails.Mobile = new TelephoneNumber();
                if (comp.ContactDetails.TelephoneAH == null)
                    comp.ContactDetails.TelephoneAH = new TelephoneNumber();

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

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

                comp.ContactDetails.Email = compDetails.Email;
                comp.ContactDetails.Fax.Number = compDetails.Fax;
                comp.ContactDetails.Mobile.Number = compDetails.Mobile;
                comp.ContactDetails.Telephone.Number = compDetails.Telephone;
                comp.ContactDetails.TelephoneAH.Number = compDetails.TelephoneAH;

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

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

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

                newNaw = new ContactsNAW(compDetails.CompanyName, 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 = compDetails.CompanyName;
                    boolNawInsert = true;
                }

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

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

                if (compID == 0 && !LoginMapper.IsLoggedInAsStichting(session))
                    comp.AssetManager = (IAssetManager)LoginMapper.GetCurrentManagmentCompany(session);

                comp.KvKNumber = compDetails.KvKNumber;

                if (comp.CurrentNAW.Name.Length > 0 &&
                     comp.KvKNumber.Length > 0 &&
                     Util.IsNotNullDate(comp.DateOfFounding) &&
                     comp.InternetEnabled != InternetEnabled.Unknown &&
                     (comp.ContactDetails != null &&
                      comp.ContactDetails.Email.Length > 0 &&
                      comp.ContactDetails.Telephone != null &&
                      comp.ContactDetails.Telephone.Number.Length > 0) &&
                     residentialAddress != null &&
                     residentialAddress.Street.Length > 0 &&
                     residentialAddress.HouseNumber.Length > 0 &&
                     residentialAddress.PostalCode.Length > 0 &&
                     residentialAddress.City.Length > 0)
                {
                    comp.StatusNAR = EnumStatusNAR.Complete;
                }
                else
                    comp.StatusNAR = EnumStatusNAR.Incomplete;

                if (comp.CreationDate.Year < 2000) comp.CreationDate = DateTime.Now;

                if (compID == 0)
                    blnSave = ContactMapper.Insert(session, comp);
                else
                    blnSave = ContactMapper.Update(session, comp);

                compID = comp.Key;
            }
            finally
            {
                session.Close();
            }
        }
Beispiel #2
0
        private static IContactCompany CreateContactCompany(IDalSession session,
                                                        string KvKNummer,
                                                        string Naam,
                                                        Address PostalAddress,
                                                        Address ResidentialAddress,
                                                        IContactDetails ContactDetails,
                                                        DateTime dateOfFounding,
                                                        IManagementCompany AssetManager,
                                                        DateTime creationdate)
        {
            IContactCompany theCompany = null;

            if (!LookupContactCompanybyKVK(session, KvKNummer, out theCompany))
            {
                theCompany = new ContactCompany(Naam, PostalAddress, ResidentialAddress, ContactDetails, KvKNummer);
            }
            theCompany.DateOfFounding = dateOfFounding;
            theCompany.AssetManager = (IAssetManager)AssetManager;
            theCompany.CreationDate = creationdate;

            return theCompany;
        }