Ejemplo n.º 1
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);
         }
     }
 }
Ejemplo n.º 2
0
 public static WishlistItem Load(Int32 wishlistItemId)
 {
     return(WishlistItemDataSource.Load(wishlistItemId, true));
 }