Пример #1
0
        public static Wishlist Load(Int32 wishlistId, bool useCache)
        {
            if (wishlistId == 0)
            {
                return(null);
            }
            Wishlist wishlist = null;
            string   key      = "Wishlist_" + wishlistId.ToString();

            if (useCache)
            {
                wishlist = ContextCache.GetObject(key) as Wishlist;
                if (wishlist != null)
                {
                    return(wishlist);
                }
            }
            wishlist = new Wishlist();
            if (wishlist.Load(wishlistId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, wishlist);
                }
                return(wishlist);
            }
            return(null);
        }
 /// <summary>
 /// Loads the given Wishlist object from the given database data reader.
 /// </summary>
 /// <param name="wishlist">The Wishlist object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(Wishlist wishlist, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     wishlist.WishlistId   = dr.GetInt32(0);
     wishlist.UserId       = dr.GetInt32(1);
     wishlist.Name         = NullableData.GetString(dr, 2);
     wishlist.ViewPassword = NullableData.GetString(dr, 3);
     wishlist.IsDirty      = false;
 }
Пример #3
0
        public static bool Delete(Int32 wishlistId)
        {
            Wishlist wishlist = new Wishlist();

            if (wishlist.Load(wishlistId))
            {
                return(wishlist.Delete());
            }
            return(false);
        }
Пример #4
0
        public static WishlistCollection LoadForUser(Int32 userId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + Wishlist.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_Wishlists");
            selectQuery.Append(" WHERE UserId = @userId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@userId", System.Data.DbType.Int32, userId);
            //EXECUTE THE COMMAND
            WishlistCollection results = new WishlistCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        Wishlist wishlist = new Wishlist();
                        Wishlist.LoadDataReader(wishlist, dr);
                        results.Add(wishlist);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
Пример #5
0
 /// <summary>
 /// Moves the source wishlist to the target wishlist.
 /// </summary>
 /// <param name="sourceId">The ID of the user with the source wishlist.</param>
 /// <param name="targetId">The ID of the user to transfer the wishlist to.</param>
 /// <param name="transferEmptyWishlist">If false, the wishlist is not transferred when the source wishlist is empty.  If true, the wishlist is always transferred.</param>
 /// <remarks>Any existing contents of the target wishlist are removed prior to transfer.</remarks>
 public static void Transfer(int sourceId, int targetId, bool transferEmptyWishlist)
 {
     if (sourceId != targetId)
     {
         //GET THE DEFAULT BASKET FOR THE SOURCE USER
         WishlistCollection sourceWishlists = WishlistDataSource.LoadForUser(sourceId);
         if (sourceWishlists.Count == 0)
         {
             return;
         }
         Wishlist sourceWishlist = sourceWishlists[0];
         if (!transferEmptyWishlist)
         {
             //WE SHOULD NOT TRANSFER EMPTY BASKETS, COUNT THE SOURCE ITEMS
             int sourceCount = WishlistItemDataSource.CountForWishlist(sourceWishlist.WishlistId);
             if (sourceCount == 0)
             {
                 return;
             }
         }
         //DETERMINE WHETHER USER HAS A WISHLIST ALREADY
         Database  database = Token.Instance.Database;
         DbCommand command  = database.GetSqlStringCommand("SELECT WishlistId FROM ac_Wishlists WHERE UserId = @targetId");
         database.AddInParameter(command, "@targetId", System.Data.DbType.Int32, targetId);
         int targetWishlistId = AlwaysConvert.ToInt(database.ExecuteScalar(command));
         if (targetWishlistId == 0)
         {
             //USER HAS NO WISHLIST, SO MOVE THE SOURCE WISHLIST TO NEW USER
             sourceWishlist.UserId = targetId;
             sourceWishlist.Save();
         }
         else
         {
             //USER HAS A WISHLIST, JUST MOVE ITEMS FROM SOURCE TO TARGET
             command = database.GetSqlStringCommand("UPDATE ac_WishlistItems SET WishlistId = @targetWishlistId WHERE WishlistId = @sourceWishlistId");
             database.AddInParameter(command, "@targetWishlistId", System.Data.DbType.Int32, targetWishlistId);
             database.AddInParameter(command, "@sourceWishlistId", System.Data.DbType.Int32, sourceWishlist.WishlistId);
             database.ExecuteNonQuery(command);
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Migrates data such as profile settings and basket contents from one user to another.
        /// </summary>
        /// <param name="oldUser">The user that provides the source data.</param>
        /// <param name="newUser">The user to receive the data.</param>
        /// <param name="includeOrderData">If true, order history and address book are migrated.</param>
        /// <param name="isNewUserAccount">If true, newUser represents an account just created.</param>
        public static void Migrate(User oldUser, User newUser, bool includeOrderData, bool isNewUserAccount)
        {
            //FAIL MIGRATION IF REQUIRED PARAMETERS MISSING
            if (oldUser == null)
            {
                throw new ArgumentNullException("oldUser");
            }
            if (newUser == null)
            {
                throw new ArgumentNullException("newUser");
            }

            //ONLY MIGRATE IF USERID DOES NOT MATCH
            if (oldUser.UserId != newUser.UserId)
            {
                //MIGRATE AFFILIATE SETTINGS
                if (oldUser.Affiliate != null && oldUser.AffiliateId != newUser.AffiliateId)
                {
                    // A VALID AFFILIATE WAS SET ON THE OLD USER AND IS NOT THE ONE ASSOCIATED WITH NEW USER
                    // SHOULD WE UPDATE THE USER?
                    StoreSettingCollection settings = Store.GetCachedSettings();
                    if (isNewUserAccount ||
                        settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersOverrideAffiliate ||
                        (settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersNoOverride && newUser.AffiliateId == 0))
                    {
                        // EITHER A NEW SIGNUP
                        // OR THE RULE IS TO ALWAYS OVERRIDE
                        // OR AN EXISTING USER WITH NO AFFILIATE SET WITH EXISTING USERS NO OVERRIDE OPTION
                        // AFFILIATE SHOULD BE UPDATED FOR THE TARGET USER
                        newUser.AffiliateId           = oldUser.AffiliateId;
                        newUser.AffiliateReferralDate = oldUser.AffiliateReferralDate;
                    }

                    // UPDATE USERS WITH NEW AFFILIATE ASSOCIATIONS
                    newUser.Save();
                    oldUser.AffiliateId           = 0;
                    oldUser.AffiliateReferralDate = DateTime.MinValue;
                    oldUser.Save();
                }

                //TRANSFER BASKET IF NEEDED
                Basket.Transfer(oldUser.UserId, newUser.UserId);
                Wishlist.Transfer(oldUser.UserId, newUser.UserId);

                // TRANSFER PAGE VIEW HISTORY
                PageViewDataSource.UpdateUser(oldUser.UserId, newUser.UserId);

                //SHOULD WE TRANSFER ORDER DATA?
                if (includeOrderData)
                {
                    //REASSIGN ORDERS AND ADDRESSES TO NEW USER
                    OrderDataSource.UpdateUser(oldUser.UserId, newUser.UserId);
                    AddressDataSource.UpdateUser(oldUser.UserId, newUser.UserId);
                }
                else if (oldUser.IsAnonymous)
                {
                    //BUG 7740, ERASE ANY ADDRESS INFO ASSOCIATED WITH ANON ACCOUNT
                    oldUser.Addresses.DeleteAll();
                    oldUser.PrimaryAddressId = 0;
                    oldUser.Save();
                }
            }
        }
Пример #7
0
 public static SaveResult Insert(Wishlist wishlist)
 {
     return(wishlist.Save());
 }
Пример #8
0
 public static SaveResult Update(Wishlist wishlist)
 {
     return(wishlist.Save());
 }
Пример #9
0
 public static bool Delete(Wishlist wishlist)
 {
     return(wishlist.Delete());
 }