public JsonResult CompleteVending(string FinishVendingString) { // Some Preprocessing JObject jObject = JObject.Parse(FinishVendingString); JArray CoinJArray = (JArray)jObject["Coins"]; Coin[] CoinsInserted = new Coin[CoinJArray.Count]; for (int i = 0; i < CoinJArray.Count; i++) { CoinsInserted[i] = new Coin(CoinJArray[i].ToString()); } string ProductName = (string)jObject["ProductName"]; decimal RemainingAmount = 0.00m; //Validate the coins bool CoinsValidated = VendingService.ValidateInsertedCoins(CoinsInserted); //Validate the product bool ProductValidated = VendingService.ValidateProduct(ProductName); //Amount to be returned decimal AmountToBeReturned = 0.00m; if (CoinsValidated && ProductValidated) { decimal TotalAmount = VendingService.SumOfCoins(CoinsInserted); //Subtract Product Count VendingService.SubtractProductCount(ProductName); //Tender the change; RemainingAmount = VendingService.TenderChange(TotalAmount, ProductName); if (RemainingAmount == 0) { AmountToBeReturned = TotalAmount - VendingService.GetProductCost(ProductName); //Add inserted coins to the existing pool of coins VendingService.AddToExistingChange(CoinsInserted); } } //It does not carry any sensitive information - So we can allow get. return(Json(new { RemainingAmount = RemainingAmount, CoinsValidated = CoinsValidated, ProductValidated = ProductValidated, AmountToBeReturned = AmountToBeReturned }, JsonRequestBehavior.AllowGet)); }