/// <summary> /// Makes product sale /// </summary> /// <param name="ProductId">Product id</param> /// <returns>Operation result</returns> public Result BuyProduct(int ProductId) { if (Products[ProductId] == 0) { return new Result { Success = false, Message = "This product has ended" } } ; var ProductType = GetProductTypeById(ProductId); if (ProductType.Price > Balance) { return(new Result { Success = false, Message = "Not enough money, top up balance" }); } if (Balance > ProductType.Price && !Acceptor.IsCoinsEnough(Balance - ProductType.Price)) { return new Result { Success = false, Message = "I can’t sell the goods, because I won’t be able to give change" } } ; Balance -= ProductType.Price; Products[ProductId] = Products[ProductId] - 1; return(new Result { Success = true, Message = "Product sold successfully" }); }
/// <summary> /// Transferring money from one vault to another /// </summary> /// <param name="Source">Source storage</param> /// <param name="Destination">Destination Storage</param> /// <param name="Sum">Amount to be transferred</param> /// <returns>true if there are enough coins in the source</returns> public static bool TransferMoney(CoinAcceptor Source, CoinAcceptor Destination, int Sum) { var Enough = Source.IsCoinsEnough(Sum); if (Enough) { Destination.Push(Source.Get(Sum)); } return(Enough); }