protected void btnSave_Click(object sender, DirectEventArgs e) { using (UnitOfWorkScope scope = new UnitOfWorkScope(true)) { var today = DateTime.Now; /*_________________________________________________________QUERIES_________________________________________________________________________________________________________*/ //Gender Types GenderType genderType = radMale.Checked ? GenderType.MaleType : GenderType.FemaleType; PartyRole lendingInstitutionPartyRole = ObjectContext.PartyRoles.SingleOrDefault(entity => entity.RoleTypeId == RoleType.LendingInstitutionType.Id); //retrieve telephone country code int countryId = int.Parse(cmbCountry.Value.ToString()); var country = ObjectContext.Countries.SingleOrDefault(entity => entity.Id == countryId); //retreive personName by personNameType string personTitle = cmbTitle.Text; string personFirstName = txtFirstName.Text; string personMiddleName = txtMiddleName.Text; string personLastName = txtLastName.Text; string personNickName = txtNickName.Text; string personNameSuffix = txtNameSuffix.Text; string personMothersMaidenName = txtMothersMaidenName.Text; /*_________________________________________________________INSERTS______________________________________________________________________________________________________________________________________________________________*/ //insert partyTypeId to Party Party party = new Party(); party.PartyType = PartyType.PersonType; //insert genderTypeId, birthdate to Person Person person = new Person(); person.GenderType = genderType; person.Birthdate = dtBirthdate.SelectedDate; Person.CreatePersonName(person, today, personTitle, personFirstName, personMiddleName, personLastName, personNameSuffix, personNickName); Person.CreateOrUpdatePersonNames(person, PersonNameType.MothersMaidenNameType, personMothersMaidenName, today); //insert partyId, roleTypeId, effectiveDate to Party Role PartyRole partyRole = new PartyRole(); partyRole.Party = party; partyRole.PartyRoleType = RoleType.ContactType.PartyRoleType; partyRole.EffectiveDate = today; //insert firstPartyRoleId, secondPartyRoleId, partyRelationshipTypeId to Party Relationship PartyRelationship partyRelationshipType = new PartyRelationship(); partyRelationshipType.PartyRole = partyRole; partyRelationshipType.PartyRole1 = lendingInstitutionPartyRole; partyRelationshipType.PartyRelType = PartyRelType.ContactRelationshipType; partyRelationshipType.EffectiveDate = today; if (!string.IsNullOrWhiteSpace(txtCellphoneNumber.Text)) { TelecommunicationsNumber specificCellphoneNumber = TelecommunicationsNumber.CreateTelecommNumberAddress(party, TelecommunicationsNumberType.PersonalMobileNumberType, today); specificCellphoneNumber.AreaCode = txtCellphoneAreaCode.Text; specificCellphoneNumber.PhoneNumber = txtCellphoneNumber.Text; specificCellphoneNumber.IsPrimary = true; } if (!string.IsNullOrWhiteSpace(txtTelephoneNumber.Text)) { TelecommunicationsNumber specificTelephoneNumber = TelecommunicationsNumber.CreateTelecommNumberAddress(party, TelecommunicationsNumberType.HomePhoneNumberType, today); specificTelephoneNumber.AreaCode = txtTelephoneAreaCode.Text; specificTelephoneNumber.PhoneNumber = txtTelephoneNumber.Text; specificTelephoneNumber.IsPrimary = true; } if (!string.IsNullOrWhiteSpace(txtEmailAddress.Text)) { ElectronicAddress specificEmailAddress = ElectronicAddress.CreateElectronicAddress(party, ElectronicAddressType.PersonalEmailAddressType, today); specificEmailAddress.ElectronicAddressString = txtEmailAddress.Text; specificEmailAddress.IsPrimary = true; } AddressType addressType = AddressType.PostalAddressType; PostalAddressType postalAddressType = PostalAddressType.HomeAddressType; //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); ObjectContext.Parties.AddObject(party); } }
//New PartyRelationship protected PartyRelationship CreatePartyRelationship(PartyRole FirstPartyRole, PartyRole SecondPartyRole, DateTime Today) { PartyRelationship NewPartyRelationship = new PartyRelationship(); NewPartyRelationship.FirstPartyRoleId = FirstPartyRole.Id; NewPartyRelationship.SecondPartyRoleId = SecondPartyRole.Id; NewPartyRelationship.PartyRelType = PartyRelType.EmploymentType; NewPartyRelationship.EffectiveDate = Today; NewPartyRelationship.EndDate = null; ObjectContext.PartyRelationships.AddObject(NewPartyRelationship); return NewPartyRelationship; }
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); }
//New Employment protected void CreateEmployment(PartyRelationship PartyRelationship, string EmploymentStatus, string Salary) { Employment NewEmployment = new Employment(); NewEmployment.PartyRelationship = PartyRelationship; NewEmployment.EmploymentStatus = EmploymentStatus; NewEmployment.Salary = Salary; ObjectContext.Employments.AddObject(NewEmployment); }