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.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.º 2
0
        /// <summary>
        /// Update profile
        /// </summary>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Profile profile = ProfileManager.Instance.GetCurrentUser(Page.User.Identity.Name);

            if (AddressForm.IsValid)
            {
                if (profile.AccountCollection.Count > 0)
                {
                    Account account = profile.AccountCollection[0];
                    UpdateAccount(ref account, AddressForm.Address);
                }
                else
                {
                    Account account = profile.AccountCollection.AddNew();
                    account.UniqueId = profile.UniqueId;

                    UpdateAccount(ref account, AddressForm.Address);
                }

                var profileService = new ProfileService();
                profileService.DeepSave(profile);
            }

            lblMessage.Text = "Your profile information has been successfully updated.<br>&nbsp;";
        }
Exemplo n.º 3
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.º 4
0
        /// <summary>
        /// Creates a new user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="isAnonymous">True if the the user anonymous.</param>
        /// <returns>A newly created user.</returns>
        public Profile CreateUser(string username, bool isAnonymous)
        {
            var profile = new Profile();

            profile.Username         = username;
            profile.ApplicationName  = ".NET Pet Shop 4.0";
            profile.IsAnonymous      = isAnonymous;
            profile.LastActivityDate = DateTime.Now;
            profile.LastUpdatedDate  = DateTime.Now;

            var profileService = new ProfileService();

            profileService.DeepSave(profile);

            return(profile);
        }
Exemplo n.º 5
0
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string itemId = Request.QueryString["addItem"];
                if (!string.IsNullOrEmpty(itemId))
                {
                    Profile profile = ProfileManager.Instance.GetCurrentUser(Page.User.Identity.Name);
                    AddCartItem(ref profile, itemId, 1);

                    var profileService = new ProfileService();
                    profileService.DeepSave(profile);

                    // Redirect to prevent duplictations in the wish list if user hits "Refresh"
                    Response.Redirect("~/WishList.aspx", true);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="isAnonymous">True if the the user anonymous.</param>
        /// <returns>A newly created user.</returns>
        public Profile CreateUser(string username, bool isAnonymous)
        {
            var profile = new Profile();
            profile.Username = username;
            profile.ApplicationName = ".NET Pet Shop 4.0";
            profile.IsAnonymous = isAnonymous;
            profile.LastActivityDate = DateTime.Now;
            profile.LastUpdatedDate = DateTime.Now;

            var profileService = new ProfileService();
            profileService.DeepSave(profile);

            return profile;
        }