public IHttpActionResult GetAllItems() { var repo = VendingMachineFactory.GetRepository(); var items = repo.GetAllItems(); return(Ok(items)); }
public static void Run() { // Create new vending machine. NewVendingMachine vendingMachine = VendingMachineFactory.CreateNewVendingMachine(); // Initialize vending machine. initializeMachine(vendingMachine); }
public IHttpActionResult GetbyId(string amount, int id) { var repo = VendingMachineFactory.GetRepository(); Item item = repo.GetItemById(id); if (item == null) { return(new HttpError("Item is not found", Request)); } if (item.quantity < 0) { return(new HttpError("Item is out of stock. Please try again.", Request)); } decimal money = decimal.Parse(amount); ReturnedChange change = new ReturnedChange(); if (money >= item.price) { money = money - item.price; change.Quarters = (int)(money / .25M); money %= .25M; change.Dimes = (int)(money / .10M); money %= .10M; change.Nickels = (int)(money / .05M); money %= .05M; change.Pennies = (int)(money / 0.01M); repo.Update(item); } else if (money < item.price) { return(new HttpError("Please enter more money.", Request)); } return(Ok(change)); }
public IHttpActionResult SelectAll() { var repo = VendingMachineFactory.GetRepository(); return(Ok(repo.GetAllItems())); }
public void Startup() { var vendingMachineFactory = new VendingMachineFactory(new TestCoinRepository()); // should rather use a builder to initialize different states of an object; (better than a factory) vendingMachine = vendingMachineFactory.CreateDollarVendingMachine(); }
protected override IVendingMachine GetVendingMachineInstance() { VendingMachineFactory vendingMachineFactory = new VendingMachineFactory(); return(vendingMachineFactory.GetInstance()); }