Soomla.Store.UpgradeVG.Take C# (CSharp) Method

Take() public method

Takes upgrade from the user, or in other words DOWNGRADES the associated VirtualGood (mGood). Checks if the current Upgrade is really associated with the VirtualGood and:
public Take ( int amount, bool notify ) : int
amount int NOT USED HERE!.
notify bool see parent.
return int
		public override int Take(int amount, bool notify) {
			VirtualGood good = null;
			
			try {
				good = (VirtualGood) StoreInfo.GetItemByItemId(GoodItemId);
			} catch (VirtualItemNotFoundException) {
				SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + GoodItemId
				                     + " doesn't exist! Can't downgrade.");
				return 0;
			}
			
			UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good);
			
			// Case: Upgrade is not assigned to this Virtual Good
			if (upgradeVG != this) {
				SoomlaUtils.LogError(TAG, "You can't take an upgrade that's not currently assigned."
				                     + "The UpgradeVG " + Name + " is not assigned to " + "the VirtualGood: "
				                     + good.Name);
				return 0;
			}
			
			if (!string.IsNullOrEmpty(PrevItemId)) {
				UpgradeVG prevUpgradeVG = null;
				// Case: downgrade is not possible because previous upgrade does not exist
				try {
					prevUpgradeVG = (UpgradeVG)StoreInfo.GetItemByItemId(PrevItemId);
				} catch (VirtualItemNotFoundException) {
					SoomlaUtils.LogError(TAG, "Previous UpgradeVG with itemId: " + PrevItemId
					                     + " doesn't exist! Can't downgrade.");
					return 0;
				}
				// Case: downgrade is successful!
				SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to: "
				                     + prevUpgradeVG.Name);
				VirtualGoodsStorage.AssignCurrentUpgrade(good, prevUpgradeVG, notify);
			}
			
			// Case: first Upgrade in the series - so we downgrade to NO upgrade.
			else {
				SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to NO-UPGRADE");
				VirtualGoodsStorage.RemoveUpgrades(good, notify);
			}

			return base.Take(amount, notify);
		}
	}