public static void CreateOrUpdateElectronicAddress(ElectronicAddress currentElectronicAddress, ElectronicAddress newElectronicAddress, DateTime now) { //check if is equal; bool equal = true; equal &= currentElectronicAddress.ElectronicAddressString == newElectronicAddress.ElectronicAddressString; if (equal == false) { currentElectronicAddress.Address.EndDate = now; Address address = new Address(); address.Party = currentElectronicAddress.Address.Party; address.AddressType = AddressType.ElectronicAddressType; address.EffectiveDate = now; newElectronicAddress.Address = address; newElectronicAddress.ElectronicAddressType = currentElectronicAddress.ElectronicAddressType; Context.ElectronicAddresses.AddObject(newElectronicAddress); } else { if (newElectronicAddress.EntityState == System.Data.EntityState.Added) Context.Detach(newElectronicAddress); } }
public static ElectronicAddress AddEmail(Address address, ElectronicAddressType type, bool isPrimary) { ElectronicAddress email = new ElectronicAddress(); email.Address = address; email.ElectronicAddressType = type; email.IsPrimary = isPrimary; return email; }
public static ElectronicAddress CreateElectronicAddress(Party party, ElectronicAddressType type, DateTime now) { Address address = new Address(); address.Party = party; address.AddressType = AddressType.ElectronicAddressType; address.EffectiveDate = now; ElectronicAddress electronicAddress = new ElectronicAddress(); electronicAddress.Address = address; electronicAddress.ElectronicAddressType = type; return electronicAddress; }
public static void CreateOrUpdateElectronicAddress(Party party, ElectronicAddress newElectronicAddress , ElectronicAddressType type, Func<Address, bool> condition, DateTime now) { var currentElectronicAddress = ElectronicAddress.GetCurrentElectronicAddress(party, type, condition); if (string.IsNullOrWhiteSpace(newElectronicAddress.ElectronicAddressString)) { if (currentElectronicAddress != null) currentElectronicAddress.Address.EndDate = now; if (newElectronicAddress.EntityState == System.Data.EntityState.Added) Context.Detach(newElectronicAddress); return; } bool isEqual = false; if (currentElectronicAddress != null) { isEqual = currentElectronicAddress.ElectronicAddressString == newElectronicAddress.ElectronicAddressString; if (isEqual == false) currentElectronicAddress.Address.EndDate = now; } if (isEqual == false) { Address address = new Address(); address.Party = party; address.AddressType = AddressType.ElectronicAddressType; address.EffectiveDate = now; newElectronicAddress.Address = address; newElectronicAddress.ElectronicAddressType = type; Context.ElectronicAddresses.AddObject(newElectronicAddress); } else { if (newElectronicAddress.EntityState == System.Data.EntityState.Added) Context.Detach(newElectronicAddress); } }
public void UpdateOrNot(PartyRole partyRole) { DateTime today = DateTime.Now; var lenderPartyRole = ObjectContext.PartyRoles.SingleOrDefault(entity => entity.RoleTypeId == RoleType.LendingInstitutionType.Id);//Lending Institution var EmployeeView = ObjectContext.EmployeeViewLists.SingleOrDefault(entity => entity.EmployeeId == partyRole.Id); var party = ObjectContext.PartyRoles.SingleOrDefault(entity => entity.Id == partyRole.Id && entity.EndDate == null).Party; var person = party.Person; var employee = ObjectContext.Employees.SingleOrDefault(entity => entity.PartyRoleId == partyRole.Id); var partyRelationShip = ObjectContext.PartyRelationships.SingleOrDefault(entity => entity.FirstPartyRoleId == partyRole.Id && entity.SecondPartyRoleId == lenderPartyRole.Id && entity.EndDate == null); var employment = ObjectContext.Employments.SingleOrDefault(entity => entity.PartyRelationshipId == partyRelationShip.Id); string concatinatedTIN = ConcatinateTIN(txtTIN.Text, txtTIN1.Text, txtTIN2.Text, txtTIN3.Text); Person.CreateOrUpdatePersonNames(person, PersonNameType.TitleType, hdnTitle.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.FirstNameType, hdnFirstName.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.MiddleNameType, hdnMiddleName.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.LastNameType, hdnLastName.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.NameSuffixType, hdnSuffix.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.NickNameType, hdnNickName.Text, today); /*------------------------------------------------------------------------------------------------------------------*/ GenderType genderType; if(radioFemale.Checked) genderType = GenderType.FemaleType; else genderType = GenderType.MaleType; if(person.GenderType != genderType) person.GenderType = genderType;//gender if(person.Birthdate != dtBirthDate.SelectedDate) person.Birthdate = dtBirthDate.SelectedDate;//birthdate string stringPersinPictureFile = hdnPersonPicture.Value.ToString(); if (person.ImageFilename != stringPersinPictureFile) person.ImageFilename = hdnPersonPicture.Value.ToString();//imagepicture if (employee.EmployeeIdNumber != txtEmployeeIdNumber.Text) { if (string.IsNullOrWhiteSpace(txtEmployeeIdNumber.Text)) { employee.EmployeeIdNumber = null; } else { employee.EmployeeIdNumber = txtEmployeeIdNumber.Text;//employeeidnumber } } if (employee.Position != cmbPosition.SelectedItem.Text) employee.Position = cmbPosition.SelectedItem.Text;//position if(employment.EmploymentStatus != cmbEmploymentStatus.SelectedItem.Text) employment.EmploymentStatus = cmbEmploymentStatus.SelectedItem.Text;//employmentstatus if(employment.Salary != txtSalary.Text) employment.Salary = txtSalary.Text;//salary Taxpayer.CreateOrUpdateTaxPayer(partyRole, concatinatedTIN);//tin if(employee.SssNumber != txtSSSNumber.Text) employee.SssNumber = txtSSSNumber.Text;//sssnumber if(employee.PhicNumber != txtPHICNumber.Text) employee.PhicNumber = txtPHICNumber.Text;//phicnumber /*------------------------------------------------------------------------------------------------------------------*/ /** CONTACT INFO DETAILS **/ /*------------------------------------------------------------------------------------------------------------------*/ //Primary Home Address PostalAddress newPostalAddress = new PostalAddress(); newPostalAddress.StreetAddress = hdnStreetAddress.Text; newPostalAddress.Barangay = hdnBarangay.Text; newPostalAddress.City = hdnCity.Text; newPostalAddress.Municipality = hdnMunicipality.Text; newPostalAddress.Province = hdnProvince.Text; newPostalAddress.State = hdnState.Text; newPostalAddress.PostalCode = hdnPostalCode.Text; newPostalAddress.CountryId = int.Parse(hdnCountryId.Text); newPostalAddress.IsPrimary = true; PostalAddress.CreateOrUpdatePostalAddress(party, newPostalAddress, PostalAddressType.HomeAddressType, today, true); //Home Phone TelecommunicationsNumber newTelePhoneNumber = new TelecommunicationsNumber(); newTelePhoneNumber.AreaCode = txtTeleAreaCode.Text; newTelePhoneNumber.PhoneNumber = txtTelePhoneNumber.Text; newTelePhoneNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.HomePhoneNumberType; newTelePhoneNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, newTelePhoneNumber, TelecommunicationsNumberType.HomePhoneNumberType, today, true); //Personal Mobile TelecommunicationsNumber newCellPhoneNumber = new TelecommunicationsNumber(); newCellPhoneNumber.AreaCode = txtCellAreaCode.Text; newCellPhoneNumber.PhoneNumber = txtCellPhoneNumber.Text; newCellPhoneNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.PersonalMobileNumberType; newCellPhoneNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, newCellPhoneNumber, TelecommunicationsNumberType.PersonalMobileNumberType, today, true); //Electronic Address ElectronicAddress newEmailAddress = new ElectronicAddress(); newEmailAddress.ElectronicAddressString = txtPrimaryEmailAddress.Text; newEmailAddress.ElectronicAddressType = ElectronicAddressType.PersonalEmailAddressType; newEmailAddress.IsPrimary = true; ElectronicAddress.CreateOrUpdateElectronicAddress(party, newEmailAddress, ElectronicAddressType.PersonalEmailAddressType, entity => entity.ElectronicAddress.IsPrimary == true, today); }
private void CreateOrUpdateContactInfo(Party party, Country country, DateTime today) { TelecommunicationsNumber faxNumber = new TelecommunicationsNumber(); faxNumber.AreaCode = this.txtFaxAreacode.Text; faxNumber.PhoneNumber = this.txtFaxNumber.Text; faxNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.BusinessFaxNumberType; faxNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, faxNumber, TelecommunicationsNumberType.BusinessFaxNumberType, today, true); TelecommunicationsNumber telephoneNumber = new TelecommunicationsNumber(); telephoneNumber.AreaCode = this.txtTelephoneAreaCode.Text; telephoneNumber.PhoneNumber = this.txtTelephoneNumber.Text; telephoneNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.BusinessPhoneNumberType; telephoneNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, telephoneNumber, TelecommunicationsNumberType.BusinessPhoneNumberType, today, true); ElectronicAddress emailAddress = new ElectronicAddress(); emailAddress.ElectronicAddressString = txtEmailAddress.Text; emailAddress.IsPrimary = true; ElectronicAddress.CreateOrUpdateElectronicAddress(party, emailAddress, ElectronicAddressType.BusinessEmailAddressType, entity => entity.ElectronicAddress.IsPrimary, today); }
private void CreateOrUpdateContactInfo(Party party, Country country, DateTime today) { TelecommunicationsNumber cellNumber = new TelecommunicationsNumber(); cellNumber.AreaCode = this.txtCellphoneAreaCode.Text; cellNumber.PhoneNumber = this.txtCellphoneNumber.Text; cellNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.PersonalMobileNumberType; cellNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, cellNumber, TelecommunicationsNumberType.PersonalMobileNumberType, today, true); TelecommunicationsNumber telephoneNumber = new TelecommunicationsNumber(); telephoneNumber.AreaCode = this.txtTelephoneAreaCode.Text; telephoneNumber.PhoneNumber = this.txtTelephoneNumber.Text; telephoneNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.HomePhoneNumberType; telephoneNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, telephoneNumber, TelecommunicationsNumberType.HomePhoneNumberType, today, true); ElectronicAddress emailAddress = new ElectronicAddress(); emailAddress.ElectronicAddressString = txtEmailAddress.Text; emailAddress.IsPrimary = true; ElectronicAddress.CreateOrUpdateElectronicAddress(party, emailAddress, ElectronicAddressType.PersonalEmailAddressType, entity => entity.ElectronicAddress.IsPrimary, today); }
//New Email Address protected void CreateEmailAddress(Address Address, ElectronicAddressType ElectronicAddressType, string ElectronicAddressString) { if (string.IsNullOrWhiteSpace(ElectronicAddressString)) { ObjectContext.Detach(Address); return; } ElectronicAddress NewEmailAddress = new ElectronicAddress(); NewEmailAddress.Address = Address; NewEmailAddress.ElectronicAddressType = ElectronicAddressType; NewEmailAddress.ElectronicAddressString = ElectronicAddressString; NewEmailAddress.IsPrimary = true; ObjectContext.ElectronicAddresses.AddObject(NewEmailAddress); }
//MAIN BUTTONS protected void btnSave_Click(object sender, DirectEventArgs e) { DateTime today = DateTime.Now; var lenderPartyRole = ObjectContext.PartyRoles.SingleOrDefault(entity => entity.RoleTypeId == RoleType.LendingInstitutionType.Id); Party party; string concatinatedTIN = ConcatinateTIN(txtTIN.Text, txtTIN1.Text, txtTIN2.Text, txtTIN3.Text); if (!string.IsNullOrWhiteSpace(hdnPickedPartyId.Text))//if the Employee is in the allowed employees { int PickedPartyId = int.Parse(hdnPickedPartyId.Text); party = Party.GetById(PickedPartyId); //Check if the new person has an employment record with another employer && end it. CheckIfHasAnotherEmployer(party); var person = party.Person; PartyRole partyRole = CreateEmployeePartyRole(party, today); CreateEmployee(partyRole, txtEmployeeIdNumber.Text, cmbPosition.SelectedItem.Text, txtSSSNumber.Text, string.Empty, string.Empty, txtPHICNumber.Text); Person.CreateOrUpdatePersonNames(person, PersonNameType.TitleType, txtTitle.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.FirstNameType, txtFirstName.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.MiddleNameType, txtMiddleName.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.LastNameType, txtLastName.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.NameSuffixType, txtSuffix.Text, today); Person.CreateOrUpdatePersonNames(person, PersonNameType.NickNameType, txtNickName.Text, today); Taxpayer.CreateOrUpdateTaxPayer(partyRole, concatinatedTIN); PartyRelationship partyRelationship = CreatePartyRelationship(partyRole, lenderPartyRole, today); CreateEmployment(partyRelationship, cmbEmploymentStatus.SelectedItem.Text, txtSalary.Text); PostalAddress newPostalAddress = new PostalAddress(); newPostalAddress.StreetAddress = txtStreetAddress.Text; newPostalAddress.Barangay = txtBarangay.Text; newPostalAddress.City = hdnCity.Text; newPostalAddress.Municipality = hdnMunicipality.Text; newPostalAddress.Province = txtProvince.Text; newPostalAddress.PostalCode = txtPostalCode.Text; newPostalAddress.CountryId = int.Parse(cmbCountry.SelectedItem.Value); newPostalAddress.IsPrimary = true; PostalAddress.CreateOrUpdatePostalAddress(party, newPostalAddress, PostalAddressType.HomeAddressType, today, true); TelecommunicationsNumber newCellNumber = new TelecommunicationsNumber(); newCellNumber.AreaCode = txtCellAreaCode.Text; newCellNumber.PhoneNumber = txtCellPhoneNumber.Text; newCellNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.PersonalMobileNumberType; newCellNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, newCellNumber, TelecommunicationsNumberType.PersonalMobileNumberType, today, true); TelecommunicationsNumber newTelePhoneNumber = new TelecommunicationsNumber(); newTelePhoneNumber.AreaCode = txtTeleAreaCode.Text; newTelePhoneNumber.PhoneNumber = txtTelePhoneNumber.Text; newTelePhoneNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.HomePhoneNumberType; newTelePhoneNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, newTelePhoneNumber, TelecommunicationsNumberType.HomePhoneNumberType, today, true); ElectronicAddress newEmailAddress = new ElectronicAddress(); newEmailAddress.ElectronicAddressString = txtPrimaryEmailAddress.Text; newEmailAddress.ElectronicAddressType = ElectronicAddressType.PersonalEmailAddressType; newEmailAddress.IsPrimary = true; ElectronicAddress.CreateOrUpdateElectronicAddress(party, newEmailAddress, ElectronicAddressType.PersonalEmailAddressType, entity => entity.ElectronicAddress.IsPrimary == true, today); } else//if Employee to be added is a new Employee with no records { int selectedCountryId = int.Parse(cmbCountry.SelectedItem.Value); var country = ObjectContext.Countries.SingleOrDefault(entity => entity.Id == selectedCountryId); party = CreateParty(); //get selected gender GenderType genderType; if(radioFemale.Checked) genderType = GenderType.FemaleType; else genderType = GenderType.MaleType; Person person = CreatePerson(party, dtBirthDate.SelectedDate, genderType, hdnPersonPicture.Value.ToString()); Person.CreatePersonName(person, today, txtTitle.Text, txtFirstName.Text, txtMiddleName.Text, txtLastName.Text, txtSuffix.Text, txtNickName.Text); PartyRole partyRole = CreateEmployeePartyRole(party, today); CreateEmployee(partyRole, txtEmployeeIdNumber.Text, cmbPosition.SelectedItem.Text, txtSSSNumber.Text, string.Empty, string.Empty, txtPHICNumber.Text); Taxpayer.CreateOrUpdateTaxPayer(partyRole, concatinatedTIN); PartyRelationship partyRelationship = CreatePartyRelationship(partyRole, lenderPartyRole, today); CreateEmployment(partyRelationship, cmbEmploymentStatus.SelectedItem.Text, txtSalary.Text); PostalAddress newPostalAddress = new PostalAddress(); newPostalAddress.StreetAddress = txtStreetAddress.Text; newPostalAddress.Barangay = txtBarangay.Text; newPostalAddress.City = hdnCity.Text; newPostalAddress.Municipality = hdnMunicipality.Text; newPostalAddress.Province = txtProvince.Text; newPostalAddress.PostalCode = txtPostalCode.Text; newPostalAddress.CountryId = int.Parse(cmbCountry.SelectedItem.Value); newPostalAddress.IsPrimary = true; PostalAddress.CreateOrUpdatePostalAddress(party, newPostalAddress, PostalAddressType.HomeAddressType, today, true); TelecommunicationsNumber newCellNumber = new TelecommunicationsNumber(); newCellNumber.AreaCode = txtCellAreaCode.Text; newCellNumber.PhoneNumber = txtCellPhoneNumber.Text; newCellNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.PersonalMobileNumberType; newCellNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, newCellNumber, TelecommunicationsNumberType.PersonalMobileNumberType, today, true); TelecommunicationsNumber newTelePhoneNumber = new TelecommunicationsNumber(); newTelePhoneNumber.AreaCode = txtTeleAreaCode.Text; newTelePhoneNumber.PhoneNumber = txtTelePhoneNumber.Text; newTelePhoneNumber.TelecommunicationsNumberType = TelecommunicationsNumberType.HomePhoneNumberType; newTelePhoneNumber.IsPrimary = true; TelecommunicationsNumber.CreateOrUpdateTeleCommNumberAddress(party, newTelePhoneNumber, TelecommunicationsNumberType.HomePhoneNumberType, today, true); ElectronicAddress newEmailAddress = new ElectronicAddress(); newEmailAddress.ElectronicAddressString = txtPrimaryEmailAddress.Text; newEmailAddress.ElectronicAddressType = ElectronicAddressType.PersonalEmailAddressType; newEmailAddress.IsPrimary = true; ElectronicAddress.CreateOrUpdateElectronicAddress(party, newEmailAddress, ElectronicAddressType.PersonalEmailAddressType, entity => entity.ElectronicAddress.IsPrimary == true, today); } ObjectContext.SaveChanges(); }