void chkUseParentShippingAddress_CheckedChanged(object sender, EventArgs e) { if (CurrentUserProfile == null) { CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex); } if (chkUseParentShippingAddress.Checked) { AddressEdit_SubShipping.Clear(); AddressEdit_SubShipping.Visible = false; if (CurrentUserProfile != null) { //CurrentUserProfile.ShippingAddressID = null; CurrentUserProfile.UseParentShipping = true; CurrentUserProfile.Save(); Page.Response.Redirect(Page.Request.Url.ToString(), true); } else { if (txtSubProfileName.Text == "" || txtSubFirstName.Text == "" || txtSubLastName.Text == "") { lblSubProfileFeedback.Text = "Please fill Basic Info before filling Shipping Info"; lblSubProfileFeedback.ForeColor = System.Drawing.Color.Red; } else { try { CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex); hccUserProfile parentProfile = hccUserProfile.GetById(CurrentParentProfileId); if (CurrentUserProfile == null && parentProfile != null) { hccUserProfile newProfile = new hccUserProfile { ParentProfileID = CurrentParentProfileId, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, IsActive = true, MembershipID = parentProfile.MembershipID }; newProfile.Save(); this.PrimaryKeyIndex = newProfile.UserProfileID; CurrentUserProfile = newProfile; } if (CurrentUserProfile != null) { CurrentUserProfile.IsActive = chkSubIsActive.Checked; if (txtSubProfileName.Text.Trim() != CurrentUserProfile.ProfileName) { CurrentUserProfile.ProfileName = txtSubProfileName.Text.Trim(); } if (txtSubFirstName.Text.Trim() != CurrentUserProfile.FirstName) { CurrentUserProfile.FirstName = txtSubFirstName.Text.Trim(); } if (txtSubLastName.Text.Trim() != CurrentUserProfile.LastName) { CurrentUserProfile.LastName = txtSubLastName.Text.Trim(); } //save addresses if (chkUseParentShippingAddress.Checked) { if (CurrentUserProfile.ShippingAddressID != 0) { CurrentUserProfile.UseParentShipping = true; //CurrentUserProfile.ShippingAddressID = parentProfile.ShippingAddressID; } else { CurrentUserProfile.UseParentShipping = true; CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex; } } else { AddressEdit_SubShipping.Save(); CurrentUserProfile.UseParentShipping = false; CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex; } //preferences SubProfilePrefsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID; SubProfilePrefsEdit1.Save(); //allergens SubProfileAllgsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID; SubProfileAllgsEdit1.Save(); CurrentUserProfile.Save(); //DisplayProfileTabs(false); lblSubProfileFeedback.Text = "Sub-Profile Saved - " + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss"); lblSubProfileFeedback.ForeColor = System.Drawing.Color.Green; OnSaved(new ControlSavedEventArgs(this.PrimaryKeyIndex)); } } catch { throw; } } } } else { AddressEdit_SubShipping.Visible = true; if (CurrentUserProfile != null) { CurrentUserProfile.UseParentShipping = false; CurrentUserProfile.Save(); } } }
protected override void SaveForm() { try { CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex); hccUserProfile parentProfile = hccUserProfile.GetById(CurrentParentProfileId); if (CurrentUserProfile == null && parentProfile != null) { hccUserProfile newProfile = new hccUserProfile { ParentProfileID = CurrentParentProfileId, CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, IsActive = true, MembershipID = parentProfile.MembershipID }; newProfile.Save(); this.PrimaryKeyIndex = newProfile.UserProfileID; CurrentUserProfile = newProfile; } if (CurrentUserProfile != null) { CurrentUserProfile.IsActive = chkSubIsActive.Checked; if (txtSubProfileName.Text.Trim() != CurrentUserProfile.ProfileName) { CurrentUserProfile.ProfileName = txtSubProfileName.Text.Trim(); } if (txtSubFirstName.Text.Trim() != CurrentUserProfile.FirstName) { CurrentUserProfile.FirstName = txtSubFirstName.Text.Trim(); } if (txtSubLastName.Text.Trim() != CurrentUserProfile.LastName) { CurrentUserProfile.LastName = txtSubLastName.Text.Trim(); } //save addresses if (chkUseParentShippingAddress.Checked) { if (CurrentUserProfile.ShippingAddressID != 0) { CurrentUserProfile.UseParentShipping = true; //CurrentUserProfile.ShippingAddressID = parentProfile.ShippingAddressID; } else { CurrentUserProfile.UseParentShipping = true; CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex; } } else { AddressEdit_SubShipping.Save(); CurrentUserProfile.UseParentShipping = false; CurrentUserProfile.ShippingAddressID = AddressEdit_SubShipping.PrimaryKeyIndex; } //preferences SubProfilePrefsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID; SubProfilePrefsEdit1.Save(); //allergens SubProfileAllgsEdit1.PrimaryKeyIndex = CurrentUserProfile.UserProfileID; SubProfileAllgsEdit1.Save(); CurrentUserProfile.Save(); } //DisplayProfileTabs(false); lblSubProfileFeedback.Text = "Sub-Profile Saved - " + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss"); lblSubProfileFeedback.ForeColor = System.Drawing.Color.Green; OnSaved(new ControlSavedEventArgs(this.PrimaryKeyIndex)); ClearForm(); } catch { throw; } }