protected void checkEmployerNames()
        {
            var today = DateTime.Now;
            var personName = txtPersonName.Text;
            //bool res = true;
            var sameName = ObjectContext.EmployersViewLists.SingleOrDefault(entity => entity.Name == personName);

            if (sameName != null)
            {
                int id = sameName.EmployerID;
                X.Msg.Confirm("Message", "An employer record with the same name already exists in the list. Do you want to create another employer record with the same name?", new JFunction("Employer.AddSameEmployer(result, id);", "result")).Show();
            }
            else
            {
                Party party = new Party();
                Person person = new Person();
                Organization org = new Organization();
                PersonName employerFName = new PersonName();
                PersonName employerLName = new PersonName();
                PersonName employerMName = new PersonName();
                PersonName employerNiName = new PersonName();
                PersonName employerNaName = new PersonName();
                PersonName employerTName = new PersonName();
                PersonName employerMMName = new PersonName();

                if (this.txtEmployerPartyType.Text == "Person")
                {
                    party.PartyType = PartyType.PersonType;

                    person.Party = party;

                    employerFName.Person = person;
                    employerFName.PersonNameType = PersonNameType.FirstNameType;
                    employerFName.Name = txtPersonFirstName.Text;
                    employerFName.EffectiveDate = today;

                    employerLName.Person = person;
                    employerLName.PersonNameType = PersonNameType.LastNameType;
                    employerLName.Name = txtPersonLastName.Text;
                    employerLName.EffectiveDate = today;

                    employerMMName.Person = person;
                    employerMMName.PersonNameType = PersonNameType.MothersMaidenNameType;
                    employerMMName.Name = txtPersonMothersMaidenName.Text;
                    employerMMName.EffectiveDate = today;

                    employerMName.Person = person;
                    employerMName.PersonNameType = PersonNameType.MiddleNameType;
                    employerMName.Name = txtPersonMiddleName.Text;
                    employerMName.EffectiveDate = today;

                    employerNaName.Person = person;
                    employerNaName.PersonNameType = PersonNameType.NameSuffixType;
                    employerNaName.Name = txtPersonNameSuffix.Text;
                    employerNaName.EffectiveDate = today;

                    employerNiName.Person = person;
                    employerNiName.PersonNameType = PersonNameType.NickNameType;
                    employerNiName.Name = txtPersonNickName.Text;
                    employerNiName.EffectiveDate = today;

                }
                else
                {
                    party.PartyType = PartyType.OrganizationType;

                    org.OrganizationName = txtOrganizationName.Text;
                    org.Party = party;
                }

                PartyRole partyRole = new PartyRole();
                partyRole.Party = party;
                partyRole.PartyRoleType.RoleType = RoleType.EmployerType;

                var res = Person.CheckEmployerName(partyRole);

                if(res != null)
                    X.Msg.Confirm("Message", "A party record with the same name already exists. Do you want to use this record to create the new employer record?", new JFunction("Employer.AddSameName(result, res);", "result")).Show();
            }
        }
        public int checkEmployerName()
        {
            var result = 0;
            var today = DateTime.Now;
            var personName = this.PersonName;

            Party party = new Party();
            Person person = new Person();
            Organization org = new Organization();
            PersonName employerFName = new PersonName();
            PersonName employerLName = new PersonName();
            PersonName employerMName = new PersonName();
            PersonName employerNiName = new PersonName();
            PersonName employerNaName = new PersonName();
            PersonName employerTName = new PersonName();
            PersonName employerMMName = new PersonName();

            party.PartyType = PartyType.PersonType;

            person.Party = party;

            if (this.txtEmployerPartyType.Text == "Person")
            {
                party.PartyType = PartyType.PersonType;

                person.Party = party;

                employerFName.Person = person;
                employerFName.PersonNameType = PersonNameType.FirstNameType;
                employerFName.Name = txtPersonFirstName.Text;
                employerFName.EffectiveDate = today;

                employerLName.Person = person;
                employerLName.PersonNameType = PersonNameType.LastNameType;
                employerLName.Name = txtPersonLastName.Text;
                employerLName.EffectiveDate = today;

                employerMMName.Person = person;
                employerMMName.PersonNameType = PersonNameType.MothersMaidenNameType;
                employerMMName.Name = txtPersonMothersMaidenName.Text;
                employerMMName.EffectiveDate = today;

                employerMName.Person = person;
                employerMName.PersonNameType = PersonNameType.MiddleNameType;
                employerMName.Name = txtPersonMiddleName.Text;
                employerMName.EffectiveDate = today;

                employerNaName.Person = person;
                employerNaName.PersonNameType = PersonNameType.NameSuffixType;
                employerNaName.Name = txtPersonNameSuffix.Text;
                employerNaName.EffectiveDate = today;

                employerNiName.Person = person;
                employerNiName.PersonNameType = PersonNameType.NickNameType;
                employerNiName.Name = txtPersonNickName.Text;
                employerNiName.EffectiveDate = today;

                employerTName.Person = person;
                employerTName.PersonNameType = PersonNameType.TitleType;
                employerTName.Name = txtPersonTitle.Text;
                employerTName.EffectiveDate = today;
            }
            else
            {
                party.PartyType = PartyType.OrganizationType;

                org.OrganizationName = txtOrganizationName.Text;
                org.Party = party;
            }

            PartyRole partyRole = new PartyRole();
            partyRole.Party = party;
            partyRole.RoleTypeId = RoleType.EmployerType.Id;

            //bool res = true;
            var sameName = Person.CheckEmployerPersonName(partyRole);

            if (sameName != null)
            {
                int id = sameName.Id;
                //X.Msg.Confirm("Message", "An employer record with the same name already exists in the list. Do you want to create another employer record with the same name?", new JFunction("Employer.AddSameEmployer(result, id);", "result")).Show();
                this.hiddenID.Value = id;
                result = 1;
            }
            else
            {

                var res = Person.CheckEmployerName(partyRole);

                if (res != null)
                {
                    //X.Msg.Confirm("Message", "A party record with the same name already exists. Do you want to use this record to create the new employer record?", new JFunction("Employer.AddSameName(result, res);", "result")).Show();
                    result = 2;
                    hiddenID.Value = res.Id;
                    hiddenExistingParty.Value = res.PartyId;
                    hiddenExistingPartyRole.Value = res.Id;

                }
            }

            return result;
        }
        private Party CreateOrRetrieveParty(FinancialEntities ctx, DateTime today)
        {
            Party party;
            int organizationTypeId = int.Parse(cmbOrganizationType.SelectedItem.Value.ToString());
            if (string.IsNullOrWhiteSpace(HiddenPartyId.Text))
            {
                var partyType = ctx.PartyTypes.First(x => x.Name.Equals("Organization"));

                party = new Party();
                party.PartyTypeId = partyType.Id;

                var roleType = ctx.RoleTypes.SingleOrDefault(entity => entity.Name.Equals("Lending Institution"));
                PartyRole newPartyRole = new PartyRole();
                newPartyRole.Party = party;
                newPartyRole.PartyRoleType = roleType.PartyRoleType;
                newPartyRole.EffectiveDate = today;

                Organization organization = new Organization();
                organization.Party = party;//
                organization.OrganizationTypeId = organizationTypeId;
                organization.OrganizationName = txtName.Text;
                organization.DateEstablished = Convert.ToDateTime(dfDateEstablished.Text);
                ctx.Parties.AddObject(party);
            }
            else
            {
                int partyId = int.Parse(HiddenPartyId.Text);
                party = ctx.Parties.SingleOrDefault(entity => entity.Id == partyId);
                Organization organization = party.Organization;
                organization.OrganizationTypeId = organizationTypeId;
                organization.OrganizationName = txtName.Text;
                organization.DateEstablished = Convert.ToDateTime(dfDateEstablished.Text);
            }
            return party;
        }
示例#4
0
        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            using (var context = new FinancialEntities())
            {
                var today = DateTime.Now;
                Bank bank = new Bank();
                Organization org = null;
                Party party = null;
                if (string.IsNullOrWhiteSpace(hiddenPartyId.Text) != false)
                {
                   party = new Party();
                   org = new Organization();
                   org.Party = party;
                   org.OrganizationName = txtName.Text;
                }
                else
                {
                   int partyId = Convert.ToInt32(hiddenPartyId.Text);
                   party = context.Parties.FirstOrDefault(entity => entity.Id == partyId);
                   org = context.Organizations.FirstOrDefault(entity => entity.PartyId == partyId);
                   org.OrganizationName = txtName.Text;
                  hiddenPartyId.Value = "";
                }
                BankStatu bankStatus = new BankStatu();

                var bankRoleType = context.RoleTypes.SingleOrDefault(entity => entity.Name == RoleTypeEnums.Bank);
                var orgPartyType = context.PartyTypes.SingleOrDefault(entity => entity.Name == PartyTypeEnums.Organization);
                var bankStatusType = context.BankStatusTypes.SingleOrDefault(entity => entity.Name == BankStatusTypeEnum.Active);

                InitialDatabaseValueChecker.ThrowIfNull<RoleType>(bankRoleType);
                InitialDatabaseValueChecker.ThrowIfNull<PartyType>(orgPartyType);
                InitialDatabaseValueChecker.ThrowIfNull<BankStatusType>(bankStatusType);

                party.PartyType = orgPartyType;

                PartyRole partyRole = new PartyRole();
                partyRole.Party = party;
                partyRole.PartyRoleType = bankRoleType.PartyRoleType;
                partyRole.EffectiveDate = today;

                bankStatus.BankStatusType = bankStatusType;
                bankStatus.PartyRoleId = partyRole.Id;
                bankStatus.EffectiveDate = today;

                bank.Branch = this.txtBranch.Text;

                if (string.IsNullOrWhiteSpace(this.txtAcronym.Text)) bank.Acronym = bank.PartyRole.Party.Organization.OrganizationName;
                else bank.Acronym = this.txtAcronym.Text;

                var addressType = context.AddressTypes.SingleOrDefault(entity => entity.Name == AddressTypeEnums.PostalAddress);
                Address postalAdd = AddressBusinessUtility.AddAddress(party, addressType, today);

                var postalAddressType = context.PostalAddressTypes.SingleOrDefault(entity => entity.Name == PostalAddressTypeEnums.BusinessAddress);
                InitialDatabaseValueChecker.ThrowIfNull<PostalAddressType>(postalAddressType);
                PostalAddress specificPostalAddress2 = AddressBusinessUtility.AddPostal(postalAdd, postalAddressType, true);
                int countryId = int.Parse(cmbCountry.Value.ToString());
                var country = context.Countries.FirstOrDefault(entity => entity.Id == countryId);
                InitialDatabaseValueChecker.ThrowIfNull<Country>(country);

                if(string.IsNullOrWhiteSpace(hiddenStreetName.Text)==false)specificPostalAddress2.StreetAddress = hiddenStreetName.Text;
                specificPostalAddress2.Barangay = hiddenBarangay.Text;
                specificPostalAddress2.PostalCode = hiddenPostalCode.Text;
                specificPostalAddress2.Country = country;
                if (string.IsNullOrWhiteSpace(hiddenCity.Text) == false) specificPostalAddress2.City = hiddenCity.Text;
                if (string.IsNullOrWhiteSpace(hiddenMunicipality.Text) == false) specificPostalAddress2.Municipality = hiddenMunicipality.Text;
                if (string.IsNullOrWhiteSpace(hiddenProvince.Text) == false) specificPostalAddress2.Province = hiddenProvince.Text;
                var telAddressType = context.AddressTypes.SingleOrDefault(entity => entity.Name == AddressTypeEnums.TelecommunicationNumber);
                if (string.IsNullOrWhiteSpace(txtAreaCode.Text) ==false)
                {
                    Address telephoneAddress = AddressBusinessUtility.AddAddress(party, telAddressType, today);
                    var telType = context.TelecommunicationsNumberTypes.SingleOrDefault(entity => entity.Name == TelecommunicationsNumberTypeEnums.BusinessPhoneNumber);
                    TelecommunicationsNumber specificTelephoneAddress = AddressBusinessUtility.AddTelNum(telephoneAddress, telType, true);
                    specificTelephoneAddress.AreaCode = txtAreaCode.Text;
                    specificTelephoneAddress.PhoneNumber = txtPhoneNum.Text;
                }
                if (string.IsNullOrWhiteSpace(txtFaxAreaCode.Text)== false)
                {
                    Address faxAddress = AddressBusinessUtility.AddAddress(party, telAddressType, today);
                    var faxType = context.TelecommunicationsNumberTypes.SingleOrDefault(entity => entity.Name == TelecommunicationsNumberTypeEnums.BusinessFaxNumber);
                    TelecommunicationsNumber specificTelephoneAddress1 = AddressBusinessUtility.AddTelNum(faxAddress, faxType, false);
                    specificTelephoneAddress1.AreaCode = txtFaxAreaCode.Text;
                    specificTelephoneAddress1.PhoneNumber = txtFaxNum.Text;
                }
                if (string.IsNullOrWhiteSpace(txtEmailAdd.Text) == false)
                {
                    var emailAddType = context.AddressTypes.SingleOrDefault(entity => entity.Name == AddressTypeEnums.ElectronicAddress);
                    var emailType = context.ElectronicAddressTypes.SingleOrDefault(entity => entity.Name == ElectronicAddressTypeEnums.BusinessEmailAddress);
                    Address email = AddressBusinessUtility.AddAddress(party, emailAddType, today);
                    ElectronicAddress specificEmail = AddressBusinessUtility.AddEmail(email, emailType, true);
                    specificEmail.ElectronicAddressString = txtEmailAdd.Text;
                }

                context.Banks.AddObject(bank);
                context.SaveChanges();
            }
            X.Msg.Alert("Message", "Bank record successfully created").Show();
        }
        private void SaveBasicOrganizationContactInformation()
        {
            var today = DateTime.Now;

            //insert partyTypeId to Party
            PartyType partyType = ObjectContext.PartyTypes.SingleOrDefault(entity => entity.Name == PartyTypeEnums.Organization);
            Party party = new Party();
            party.PartyType = partyType;

            //insert organizationType, organizationName and dateEstablished to Organization
            OrganizationType internalOrganization = ObjectContext.OrganizationTypes.SingleOrDefault(entity => entity.Name == OrganizationTypeEnums.Internal);
            OrganizationType externalOrganization = ObjectContext.OrganizationTypes.SingleOrDefault(entity => entity.Name == OrganizationTypeEnums.External);
            Organization organization = new Organization();
            organization.OrganizationName = txtName.Text;
            if (!string.IsNullOrWhiteSpace(cmbOrganizationType.SelectedItem.Text))
            {
                int organizationTypeId = int.Parse(cmbOrganizationType.Value.ToString());
                var organizationType = ObjectContext.OrganizationTypes.SingleOrDefault(entity => entity.Id == organizationTypeId);
                organization.OrganizationType = organizationType;
            }
            else
            {
                organization.OrganizationTypeId = null;
            }
            if (dtDateEstablished.SelectedValue != null)
                organization.DateEstablished = dtDateEstablished.SelectedDate;
            else
                organization.DateEstablished = null;

            //retirieve contactRoleType from Role Type where name = "Contact"
            var contactRoleType = ObjectContext.RoleTypes.SingleOrDefault(entity => entity.Name == RoleTypeEnums.Contact);

            //insert partyId, contactRoleType and effectiveDate to Party Role
            PartyRole partyRole = new PartyRole();
            partyRole.Party = party;
            partyRole.PartyRoleType = contactRoleType.PartyRoleType;
            partyRole.EffectiveDate = today;

            //insert firstPartyRoleId, secondPartyRoleId and EffectiveDate to PartyRelationship
            var contactRelationshipType = ObjectContext.PartyRelTypes.SingleOrDefault(entity => entity.Name == PartyRelationTypesEnums.ContactRelationship);
            RoleType lendingInstitution = ObjectContext.RoleTypes.SingleOrDefault(entity => entity.Name == RoleTypeEnums.LendingInstitution);
            PartyRole lendingInstitutionPartyRole = ObjectContext.PartyRoles.SingleOrDefault(entity => entity.RoleTypeId == lendingInstitution.Id);
            PartyRelationship partyRelationship = new PartyRelationship();
            partyRelationship.PartyRole = partyRole;
            partyRelationship.PartyRole1 = lendingInstitutionPartyRole;
            partyRelationship.PartyRelType = contactRelationshipType;
            partyRelationship.EffectiveDate = today;

            //retrieve postalAddressCategoryType from AddressType where name = "Postal Address"
            var postalAddressCategoryType = ObjectContext.AddressTypes.SingleOrDefault(entity => entity.Name == AddressTypeEnums.PostalAddress);

            //retrieve businessAddressCategory from Address where addressType = postalAddressCategoryType and name = "Business Address"
            var primaryBusinessAddress = ObjectContext.PostalAddressTypes.SingleOrDefault(entity => entity.Name == PostalAddressTypeEnums.BusinessAddress);

            //insert address
            int countryId = int.Parse(cmbCountry.Value.ToString());
            var country = ObjectContext.Countries.SingleOrDefault(entity => entity.Id == countryId);

            AddressType addressType = AddressType.PostalAddressType;
            PostalAddressType postalAddressType = PostalAddressType.BusinessAddressType;

            //Create an Address with AddressType as Postal Address
            PostalAddress newPostalAddress = new PostalAddress();
            newPostalAddress.Country = country;
            newPostalAddress.Barangay = hiddenBarangay.Text;
            newPostalAddress.PostalCode = hiddenPostalCode.Text;
            newPostalAddress.Province = hiddenProvince.Text;
            newPostalAddress.City = hiddenCity.Text;
            newPostalAddress.Municipality = hiddenMunicipality.Text;
            newPostalAddress.StreetAddress = hiddenStreet.Text;
            newPostalAddress.IsPrimary = true;

            PostalAddress.CreateOrUpdatePostalAddress(party, newPostalAddress, postalAddressType, today, true);
            //retrieve telecommunicationNumberType

            if (!string.IsNullOrWhiteSpace(txtFaxNumber.Text))
            {
                TelecommunicationsNumber specificCellphoneNumber = TelecommunicationsNumber.CreateTelecommNumberAddress(party, TelecommunicationsNumberType.BusinessFaxNumberType, today);
                specificCellphoneNumber.AreaCode = txtFaxAreaCode.Text;
                specificCellphoneNumber.PhoneNumber = txtFaxNumber.Text;
                specificCellphoneNumber.IsPrimary = true;
            }

            if (!string.IsNullOrWhiteSpace(txtTelephoneNumber.Text))
            {
                TelecommunicationsNumber specificTelephoneNumber = TelecommunicationsNumber.CreateTelecommNumberAddress(party, TelecommunicationsNumberType.BusinessPhoneNumberType, today);
                specificTelephoneNumber.AreaCode = txtTelephoneAreaCode.Text;
                specificTelephoneNumber.PhoneNumber = txtTelephoneNumber.Text;
                specificTelephoneNumber.IsPrimary = true;
            }

            if (!string.IsNullOrWhiteSpace(txtEmailAddress.Text))
            {
                ElectronicAddress specificEmailAddress = ElectronicAddress.CreateElectronicAddress(party, ElectronicAddressType.BusinessEmailAddressType, today);
                specificEmailAddress.ElectronicAddressString = txtEmailAddress.Text;
                specificEmailAddress.IsPrimary = true;
            }

            ObjectContext.Parties.AddObject(party);
        }