public CurrentUserProfile GetTokenAndCurrentUserProfile(string redirectUrl) { // Validate if (string.IsNullOrEmpty(redirectUrl)) { throw new Exception("Please provide a valid url to redirect"); } string url = HttpContext.Current.Request.Url.ToString(); const string codeString = "code="; if (url.Contains(codeString)) { // exchange for token int codePosition = url.IndexOf(codeString); string[] info = url.Substring(codePosition + codeString.Length).Split('&'); Token token = GetToken(redirectUrl, info[0]); // get user profile UserProfile userProfile = GetUserProfile(token.access_token, null); CurrentUserProfile currentUserProfile = new CurrentUserProfile { UserProfile = userProfile, AgencyName = info[1].Split('=')[1], AgencyEnvironment = info[2].Split('=')[1], Token = token }; return(currentUserProfile); } return(null); }
protected void UserProfileInfo_ControlSaved(object sender, EventArgs e) // Shipping address { if (CurrentUserProfile == null) { CurrentUserProfile = hccUserProfile.GetParentProfileBy(CurrentAspNetId.Value); } if (CurrentUserProfile != null) { CurrentUserProfile.ShippingAddressID = AddressEdit_Shipping1.PrimaryKeyIndex; CurrentUserProfile.Save(); } // some profile value changed, make sure order numbers for current cart are still inline with one another SessionManager.CurrentUserProfileInfoChanged = true; }
void BillingInfoEdit1_ControlSaved(object sender, ControlSavedEventArgs e) { if (CurrentUserProfile == null) { CurrentUserProfile = hccUserProfile.GetParentProfileBy(CurrentAspNetId.Value); } if (CurrentUserProfile != null) { CurrentUserProfile.BillingAddressID = BillingInfoEdit1.CurrentBillingAddressID; CurrentUserProfile.Save(); } // some profile value changed, make sure order numbers for current cart are still inline with one another SessionManager.CurrentUserProfileInfoChanged = true; ProfileCartEdit1.Bind(); }
protected override void SaveForm() { try { if (CurrentUserProfile == null) { CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex); } //If PrimaryKeyIndex was not found, then there are no preferences to be saved. if (CurrentUserProfile == null) { return; } List <hccUserProfilePreference> existingUserPrefs = hccUserProfilePreference.GetBy(CurrentUserProfile.UserProfileID, true); existingUserPrefs.ForEach(delegate(hccUserProfilePreference userPref) { userPref.Delete(); }); foreach (ListItem item in cblPreferences.Items) { if (item.Selected) { hccUserProfilePreference newPref = new hccUserProfilePreference { PreferenceID = int.Parse(item.Value), UserProfileID = CurrentUserProfile.UserProfileID, IsActive = true }; newPref.Save(); } } CurrentUserProfile.Save(); lblFeedback.Text = "Preferences saved."; } catch (Exception) { throw; } }
protected override void SaveForm() { try { if (CurrentUserProfile == null) { CurrentUserProfile = hccUserProfile.GetById(this.PrimaryKeyIndex); } if (CurrentUserProfile == null) { return; } List <hccUserProfileAllergen> existingAllergen = hccUserProfileAllergen.GetBy(CurrentUserProfile.UserProfileID, true); existingAllergen.ForEach(a => a.Delete()); foreach (ListItem item in cblAllergens.Items) { if (item.Selected) { hccUserProfileAllergen all = new hccUserProfileAllergen { AllergenID = (int.Parse(item.Value)), UserProfileID = CurrentUserProfile.UserProfileID, IsActive = true }; all.Save(); } } CurrentUserProfile.Save(); lblFeedback.Text = "Allergens saved."; } catch (Exception) { throw; } }
public ActionResult Index() { try { CurrentUserProfile userProfile = AuthLibrary.GetCurrentUserProfile(ConfigurationManager.AppSettings["RedirectUrl"], applicationInfo); if (userProfile != null) { // good to do something here and take to next page return(View("Authenticated", userProfile)); } else { return(View("Index")); } } catch (Exception e) { // display error ViewBag.Message = e.Message; return(View("Index")); } }
void BindgvwSubProfiles() { try { List <hccUserProfile> subProfiles = new List <hccUserProfile>(); if (CurrentAspNetId.HasValue) { CurrentUserProfile = hccUserProfile.GetParentProfileBy(CurrentAspNetId.Value); } if (CurrentUserProfile != null) { subProfiles = CurrentUserProfile.GetSubProfiles(); } gvwSubProfiles.DataSource = subProfiles; gvwSubProfiles.DataBind(); } catch { throw; } }
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; } }