private void SavePurchaseUpdatesToDB() { if (PurchaseInfoIsVisible && PurchaseInfo != null) { UpdatePurchaseInfoCurrencies(); if (Quantity > PurchasedItem.Quantity) { // too much!! can't buy this many. :( _failureSoundPlayer.Play(); QuantityErrorMessage = "Quantity to purchase is higher than the number of available items"; } else { QuantityErrorMessage = ""; PurchaseInfo.QuantitySold = Quantity; var paidAsDecimal = 0m; if (!decimal.TryParse(PaidAmount, out paidAsDecimal)) { paidAsDecimal = 0; } PurchaseInfo.Paid = paidAsDecimal; if (_amountInventoryChanged != Quantity) { if (_amountInventoryChanged < Quantity) // e.g. 1 -> 3 (= diff of 2; needs to be adjusted by -2) { PurchasedItem.AdjustQuantityByAmount(_amountInventoryChanged - Quantity); } else // e.g. 3 -> 1 (= diff of 2; needs to be adjusted by 2) { PurchasedItem.AdjustQuantityByAmount(Quantity - _amountInventoryChanged); } _amountInventoryChanged = Quantity; } PurchaseInfo.SaveUpdates(); } } }