public IHttpActionResult GetAllItems() { var repo = VendingMachineFactory.GetRepository(); var items = repo.GetAllItems(); return(Ok(items)); }
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())); }