示例#1
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();
        }
示例#2
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);
            }
        }
示例#3
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);
        }
示例#4
0
        public void MigrateAnonymous(Guid AnonymousKey)
        {
            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 = UserKey;
                    cmd.Parameters.Add("AnonID", System.Data.SqlDbType.UniqueIdentifier).Value = AnonymousKey;
                    cmd.Connection.Open();
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
            }

            //ProfileManager.DeleteProfile(e.AnonymousID);
            AnonymousIdentificationModule.ClearAnonymousIdentifier();
        }
示例#5
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 { }
        }
示例#6
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 {
            }
        }
示例#7
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();
        }
示例#8
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);
        }
示例#9
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);
        }
示例#10
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();
            }
        }
示例#11
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();
        }
示例#12
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();
        }
示例#13
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();
 }
示例#14
0
 public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs e)
 {
     AnonymousIdentificationModule.ClearAnonymousIdentifier();
 }