Exemplo n.º 1
0
        // Carry over profile property values from an anonymous to an authenticated state
        protected void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e)
        {
            Profile anonymousProfile = PB.ProfileManager.Instance.GetAnonymousUser();
            Profile profile          = PB.ProfileManager.Instance.GetCurrentUser(e.Context.User.Identity.Name);

            //Merge anonymous shopping cart items to the authenticated shopping cart items
            foreach (Cart item in anonymousProfile.ShoppingCart)
            {
                profile.ShoppingCart.Add(item.ItemId, profile.UniqueID, true, item.Quantity);
            }

            //Merge anonymous wishlist items to the authenticated wishlist items
            foreach (Cart item in anonymousProfile.WishList)
            {
                profile.WishList.Add(item.ItemId, profile.UniqueID, false, item.Quantity);
            }

            profile = profile.Save();

            //Clear the cart.
            anonymousProfile.ShoppingCart.Clear();
            anonymousProfile.WishList.Clear();
            anonymousProfile = anonymousProfile.Save();

            // Clean up anonymous profile
            //ProfileManager.DeleteProfile(e.AnonymousID);
            //AnonymousIdentificationModule.ClearAnonymousIdentifier();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Profile migrate from anonymous.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="pe">The <see cref="ProfileMigrateEventArgs"/> instance containing the event data.</param>
        private void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe)
        {
            var client = ServiceLocator.Current.GetInstance <OrderClient>();
            var orders = client.GetAllCustomerOrders(pe.AnonymousID,
                                                     UserHelper.CustomerSession.StoreId);

            if (orders != null)
            {
                foreach (var order in orders)
                {
                    order.CustomerId   = UserHelper.CustomerSession.CustomerId;
                    order.CustomerName = UserHelper.CustomerSession.CustomerName;
                }

                client.SaveChanges();
            }

            // Migrate shopping cart
            var cart          = new CartHelper(CartHelper.CartName);
            var anonymousCart = new CartHelper(CartHelper.CartName, pe.AnonymousID);

            // Only perform merge if cart is not empty
            if (!anonymousCart.IsEmpty)
            {
                // Merge cart
                cart.Add(anonymousCart.Cart, true);
                cart.SaveChanges();

                // Delete anonymous cart
                anonymousCart.Delete();
                anonymousCart.SaveChanges();
            }

            var wishList          = new CartHelper(CartHelper.WishListName);
            var anonymousWishList = new CartHelper(CartHelper.WishListName, pe.AnonymousID);

            // Only perform merge if cart is not empty
            if (!anonymousWishList.IsEmpty)
            {
                // Merge wish list
                wishList.Add(anonymousWishList.Cart, true);
                if (String.IsNullOrEmpty(wishList.Cart.BillingCurrency))
                {
                    wishList.Cart.BillingCurrency = UserHelper.CustomerSession.Currency;
                }
                wishList.SaveChanges();

                // Delete anonymous wish list
                anonymousWishList.Delete();
                anonymousWishList.SaveChanges();
            }

            //Delete the anonymous data from the database
            //ProfileManager.DeleteProfile(pe.AnonymousID);

            //Remove the anonymous identifier from the request so
            //this event will no longer fire for a logged-in user
            AnonymousIdentificationModule.ClearAnonymousIdentifier();
        }
        public void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e)
        {
            var portalAreaRegistrationState = Application[typeof(IPortalAreaRegistrationState).FullName] as IPortalAreaRegistrationState;

            if (portalAreaRegistrationState != null)
            {
                portalAreaRegistrationState.OnProfile_MigrateAnonymous(sender, e);
            }
        }
Exemplo n.º 4
0
        public void OnProfile_MigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            var handler = Profile_MigrateAnonymous;

            if (handler != null)
            {
                handler(sender, args);
            }
        }
Exemplo n.º 5
0
        protected void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            try
            {
                AnonymousIdentificationModule.ClearAnonymousIdentifier();

                new Auth().SetMigrateAnonymous();
            }
            catch (Exception ex) {
                Log.Error(string.Format("Profile_OnMigrateAnonymous--ex:{0}", ex.Message), ex);
            }
        }
Exemplo n.º 6
0
        protected void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            //CustomProfileCommon profile = new CustomProfileCommon();
            //CustomProfileCommon anonymousProfile = profile.GetProfile(args.AnonymousID, false);

            ProfileManager.DeleteProfile(args.AnonymousID);
            AnonymousIdentificationModule.ClearAnonymousIdentifier();

            //profile.Save();

            // Delete the user row that was created for the anonymous user.
            Membership.DeleteUser(args.AnonymousID, true);
        }
Exemplo n.º 7
0
        private void OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            string newId = _customerService.GetCurrentUserId();

            try
            {
                _customerService.MigrateUser(args.AnonymousID, newId);
            }
            catch (Exception e)
            {
                _log.Error("Cannot migrate Sannsyn user", e);
            }
            _log.Debug("Migrating from: {0} to: {1}", args.AnonymousID, newId);
        }
Exemplo n.º 8
0
        protected void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            AnonymousIdentificationModule.ClearAnonymousIdentifier();

            try
            {
                var userId    = WebCommon.GetUserId();
                var menuBll   = new SiteMenus();
                var accessIds = new List <string>();
                accessIds.Add(userId.ToString());
                Task[] tasks = new Task[3];
                tasks[0] = Task.Factory.StartNew(() =>
                {
                    var roleIds = new SiteRoles().GetAspnetRoleIds(Roles.GetRolesForUser());
                    foreach (var item in roleIds)
                    {
                        accessIds.Add(item.ToString());
                    }
                });
                var userProfileInfo = new UserProfileInfo();
                tasks[1] = Task.Factory.StartNew(() =>
                {
                    var fuInfo = new FeatureUser().GetModel(userId, "UserProfile");
                    if (fuInfo != null)
                    {
                        userProfileInfo.SiteCode    = fuInfo.SiteCode;
                        userProfileInfo.SiteTitle   = fuInfo.SiteTitle;
                        userProfileInfo.SiteLogo    = string.IsNullOrWhiteSpace(fuInfo.SiteLogo) ? "" : WebCommon.GetSiteAppName() + fuInfo.SiteLogo;
                        userProfileInfo.CultureName = fuInfo.CultureName;
                    }
                });
                IList <SiteMenusInfo> maList = new List <SiteMenusInfo>();
                tasks[2] = Task.Factory.StartNew(() =>
                {
                    maList = menuBll.GetMenusAccess(Membership.ApplicationName, accessIds.ToArray(), User.IsInRole("Administrators"));
                });
                Task.WaitAll(tasks);

                var Profile = new CustomProfileCommon();
                Profile.UserMenus = JsonConvert.SerializeObject(maList);
                Profile.UserInfo  = JsonConvert.SerializeObject(userProfileInfo);

                Profile.Save();
            }
            catch { }
        }
Exemplo n.º 9
0
        protected void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            AnonymousIdentificationModule.ClearAnonymousIdentifier();
            Membership.DeleteUser(args.AnonymousID, true);

            try
            {
                string[] userRoles          = Roles.GetRolesForUser();
                var      menuBll            = new Menus();
                var      userMenuAccessList = menuBll.GetUserMenuAccessList(WebCommon.GetUserId(), userRoles);

                CustomProfileCommon profile = new CustomProfileCommon();
                profile.UserMenus = JsonConvert.SerializeObject(userMenuAccessList);
                profile.Save();
            }
            catch {
            }
        }
Exemplo n.º 10
0
        public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            ProfileCommon profile          = ProfileCommon.GetProfile();
            ProfileCommon anonymousProfile = ProfileCommon.GetProfile(args.AnonymousID);

            if (anonymousProfile.RecentSearch.Keywords != null)
            {
                profile.RecentSearch.Keywords = anonymousProfile.RecentSearch.Keywords;
            }


            ////////
            // Delete the anonymous profile. If the anonymous ID is not
            // needed in the rest of the site, remove the anonymous cookie.

            ProfileManager.DeleteProfile(args.AnonymousID);
            AnonymousIdentificationModule.ClearAnonymousIdentifier();

            // Delete the user row that was created for the anonymous user.
            Membership.DeleteUser(args.AnonymousID, true);
        }
Exemplo n.º 11
0
        void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e)
        {
            using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("usp_MigrateOnLogin", cn)) {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("UserID", System.Data.SqlDbType.UniqueIdentifier).Value = new Guid(Membership.GetUser().ProviderUserKey.ToString());
                    cmd.Parameters.Add("AnonID", System.Data.SqlDbType.UniqueIdentifier).Value = new Guid(e.AnonymousID);
                    cmd.Connection.Open();
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
            }

            //Profile.shipping_ZipPostal = anonProfile.shipping_ZipPostal;
            //if (anonProfile.ShoppingCart.Count > 0) {
            //	Profile.ShoppingCart = anonProfile.ShoppingCart;
            //}

            //ProfileManager.DeleteProfile(e.AnonymousID);
            AnonymousIdentificationModule.ClearAnonymousIdentifier();
        }
Exemplo n.º 12
0
        void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e)
        {
            //    try
            //    {
            //        App_Code.RALTProfile annProfile = new App_Code.RALTProfile();

            //        annProfile = annProfile.GetRALTProfile(e.AnonymousID);

            //        if (annProfile.CopyFlag == false)
            //        {

            //            App_Code.RALTProfile MyProfile = new App_Code.RALTProfile();

            //            MyProfile = MyProfile.GetRALTProfile();

            //            //CopyData
            //            MyProfile.CopyFlag = true;
            //            MyProfile.Email = annProfile.Email;
            //            MyProfile.FirstName = annProfile.FirstName;
            //            MyProfile.Language = annProfile.Language;
            //            MyProfile.LastName = annProfile.LastName;
            //            MyProfile.LastUpdatedDate = annProfile.LastUpdatedDate;
            //            MyProfile.LastVisitedDate = annProfile.LastVisitedDate;
            //            MyProfile.ProfileType = "Account";
            //            MyProfile.SpanishLevel = annProfile.SpanishLevel;
            //            MyProfile.IsAnonymous = false;

            //            MyProfile.SaveRALTProfile(MyProfile);

            //            annProfile.CopyFlag = true;
            //            annProfile.ProfileType = "Account";
            //            annProfile.SaveRALTProfile(annProfile);

            //            // AnonymousIdentificationModule.ClearAnonymousIdentifier();
            //        }
            //    }
            //    catch { }
        }
Exemplo n.º 13
0
        protected void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs args)
        {
            //TODO: maybe support capturing profile properties for anonymous users
            // then if they register transfer them to the new user


            //WebProfile anonymousProfile = new WebProfile(args.Context.Profile);


            //Profile.ZipCode = anonymousProfile;
            //Profile.CityAndState = anonymousProfile.CityAndState;
            //Profile.StockSymbols = anonymousProfile.StockSymbols;

            ////////
            // Delete the anonymous profile. If the anonymous ID is not
            // needed in the rest of the site, remove the anonymous cookie.

            //ProfileManager.DeleteProfile(args.AnonymousID);
            //AnonymousIdentificationModule.ClearAnonymousIdentifier();

            // Delete the user row that was created for the anonymous user.
            //Membership.DeleteUser(args.AnonymousID, true);
        }
Exemplo n.º 14
0
        // Carry over profile property values from an anonymous to an authenticated state
        protected void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e)
        {
            Profile anonymousProfile = PB.ProfileManager.Instance.GetAnonymousUser();
            Profile profile          = PB.ProfileManager.Instance.GetCurrentUser(e.Context.User.Identity.Name);

            //Merge anonymous shopping cart items to the authenticated shopping cart items
            foreach (Cart item in anonymousProfile.CartCollection)
            {
                profile.CartCollection.Add(new Cart()
                {
                    ItemId = item.ItemId, UniqueId = profile.UniqueId, IsShoppingCart = true, Quantity = item.Quantity
                });
            }

            //Merge anonymous wishlist items to the authenticated wishlist items
            foreach (Cart item in anonymousProfile.WishList)
            {
                profile.WishList.Add(new Cart()
                {
                    ItemId = item.ItemId, UniqueId = profile.UniqueId, IsShoppingCart = false, Quantity = item.Quantity
                });
            }


            var profileService = new ProfileService();

            profileService.DeepSave(profile);

            // Clean up anonymous profile
            ProfileManager.DeleteProfile(e.AnonymousID);
            AnonymousIdentificationModule.ClearAnonymousIdentifier();

            //Clear the cart.
            anonymousProfile.CartCollection.Clear();
            anonymousProfile.WishList.Clear();
            profileService.DeepSave(anonymousProfile);
        }
Exemplo n.º 15
0
        void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e)
        {
            Profile Profile     = new Profile();
            Profile anonProfile = Profile.GetProfile(e.AnonymousID);

            // Merge anonymous shopping cart items to the authenticated shopping cart items
            foreach (CartItemInfo cartItem in anonProfile.ShoppingCart.CartItems)
            {
                Profile.ShoppingCart.Add(cartItem);
            }

            // Merge anonymous wishlist items to the authenticated wishlist items
            foreach (CartItemInfo cartItem in anonProfile.WishList.CartItems)
            {
                Profile.WishList.Add(cartItem);
            }

            // Clean up anonymous profile
            ProfileManager.DeleteProfile(e.AnonymousID);
            AnonymousIdentificationModule.ClearAnonymousIdentifier();

            // Save profile
            Profile.Save();
        }
Exemplo n.º 16
0
        private void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            SessionWrapper wrapper = SessionManager.GetSessionWrapper();

            try
            {
                IUserProfileDao profileDao = OrnamentContext.DaoFactory.MemberShipFactory.CreateProfileDao();
                ProfileValue    anonymous  = profileDao.FindByLoginId(args.AnonymousID);
                if (anonymous != null)
                {
                    //合并anonymous profile
                    ProfileBase currenProfile = HttpContext.Current.Profile;
                    foreach (string key in anonymous.Properities.Keys)
                    {
                        currenProfile.SetPropertyValue(key, anonymous.Properities[key]);
                    }
                    profileDao.Delete(anonymous);
                    currenProfile.Save();
                    AnonymousIdentificationModule.ClearAnonymousIdentifier();
                }


                //最后,一更新Multi-lang的cookie,因此使用Profile的语言。
                OrnamentContext.MemberShip.SwitchLanguage(OrnamentContext.MemberShip.CurrentUser().GetLanguage());
                wrapper.Commit();
            }
            catch (Exception ex)
            {
                ILog log = LogManager.GetLogger(typeof(GlobalContext));
                log.Error(ex.Message, ex);
            }
            finally
            {
                wrapper.Close();
            }
        }
Exemplo n.º 17
0
 public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs e)
 {
     AnonymousIdentificationModule.ClearAnonymousIdentifier();
 }
Exemplo n.º 18
0
        protected static void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e)
        {
            // transfer the anonyous shopping cart items to the authenticated shopping cart

            var visitorId = e.AnonymousID;
            var portal    = PortalCrmConfigurationManager.CreatePortalContext();

            using (var context = PortalCrmConfigurationManager.CreateServiceContext())
            {
                if (!AdxstudioCrmConfigurationManager.TryAssertSolutionName(PortalSolutions.SolutionNames.CommerceSolutionName))
                {
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Execution aborted. {0} has not been imported.", PortalSolutions.SolutionNames.CommerceSolutionName));
                    return;
                }

                var website = context.CreateQuery("adx_website").First(ws => ws.GetAttributeValue <Guid>("adx_websiteid") == portal.Website.Id);
                //var visitorBaseCart = context.GetCartsForVisitor(visitorId, website).FirstOrDefault() as Adx_shoppingcart;
                var visitorCart = context.GetCartsForVisitor(visitorId, website).FirstOrDefault();

                if (visitorCart != null)
                {
                    var contactCartBase = context.GetCartsForContact(portal.User, website).FirstOrDefault();

                    var contactCart = contactCartBase != null ? new ShoppingCart((contactCartBase), context) : null;

                    if (contactCart != null)
                    {
                        // merge the anonymous cart with the authenticated cart

                        foreach (var item in visitorCart.GetRelatedEntities(context, new Relationship("adx_shoppingcart_shoppingcartitem")))
                        {
                            if (item.GetAttributeValue <EntityReference>("adx_productid") == null)
                            {
                                continue;
                            }

                            contactCart.AddProductToCart(item.GetAttributeValue <EntityReference>("adx_productid").Id, PriceListName, (int)item.GetAttributeValue <decimal>("adx_quantity"));
                        }

                        if (!context.IsAttached(visitorCart))
                        {
                            context.Attach(visitorCart);
                        }

                        context.DeleteObject(visitorCart);
                    }
                    else
                    {
                        // transfer the cart directly

                        const string nameFormat = "Cart for {0}";

                        var contact = portal.User;

                        if (contact != null)
                        {
                            visitorCart.SetAttributeValue("adx_name", string.Format(nameFormat, contact.GetAttributeValue <string>("fullname")));
                        }

                        visitorCart.SetAttributeValue("adx_visitorid", string.Empty);
                        visitorCart.SetAttributeValue("adx_contactid", portal.User.ToEntityReference());

                        if (!context.IsAttached(visitorCart))
                        {
                            context.Attach(visitorCart);
                        }

                        context.UpdateObject(visitorCart);
                    }

                    if (!context.IsAttached(visitorCart))
                    {
                        context.Attach(visitorCart);
                    }

                    context.SaveChanges();
                }
            }

            AnonymousIdentificationModule.ClearAnonymousIdentifier();
        }
Exemplo n.º 19
0
 /// <summary>
 /// Handles the OnMigrateAnonymous event of the Profile control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="T:System.Web.Profile.ProfileMigrateEventArgs"/> instance containing the event data.</param>
 public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
 {
     OrderController.MigrateCart(args.AnonymousID, WebProfile.Current.UserName);
     ProfileManager.DeleteProfile(args.AnonymousID);
     AnonymousIdentificationModule.ClearAnonymousIdentifier();
 }