public ChangeResponse CoinReturn(ChangeRequest transaction) { var coinCount = new Change(); coinCount.SilverDollars = transaction.ChangeOwed / 100; coinCount.Quarters = (transaction.ChangeOwed - coinCount.SilverDollars * 100) / 25; coinCount.Dimes = (transaction.ChangeOwed - (coinCount.SilverDollars * 100 + coinCount.Quarters * 25)) / 10; coinCount.Nickels = (transaction.ChangeOwed - (coinCount.SilverDollars * 100 + coinCount.Quarters * 25 + coinCount.Dimes * 10)) / 5; coinCount.Pennies = (transaction.ChangeOwed - (coinCount.SilverDollars * 100 + coinCount.Quarters * 25 + coinCount.Dimes * 10 + coinCount.Nickels * 5)); var changeResponse = new ChangeResponse(); changeResponse.Coins = coinCount; // changeResponse.Item = transaction.Item; changeResponse.ChangeOwed = (transaction.ChangeOwed); changeResponse.Payment = (transaction.Payment); changeResponse.ChangeOwed = changeResponse.ChangeOwed/100; changeResponse.Payment = changeResponse.Payment/100; return changeResponse; }
public ChangeResponse MakeChange(ChangeRequest transaction) { var changeResponse = CoinReturn(transaction); return changeResponse; }
public ActionResult VendingMachine(VendingTool model) { if (ModelState.IsValid) {//need to add validation for insufficient funds var request = new ChangeRequest(); request.Payment = (int)(model.Payment.Value*100); request.Price = (int)(model.Item.Price*100); request.ChangeOwed =request.Payment-request.Price; var cm = new ChangeMaker(); var response= cm.MakeChange(request); return View("VendingResult", response); } var itemList = new List<VendingItem> //Hard coded until I can figure out how to get filereader to find my txt file. { new VendingItem() {Name = "Starburst - $1.25", Price = 1.25M}, new VendingItem() {Name = "French Fries - $2.05", Price = 2.05M}, new VendingItem() {Name = "Butterfingers - $1.25", Price = 1.35M}, new VendingItem() {Name = "Puppy - $0.89", Price = .89M} }; model.Items = itemList; return View("VendingMachine", model); }