예제 #1
0
        public IHttpActionResult vendItems(decimal money, int id)
        {
            var repo = VendingMachineRepoFactory.GetRepository();

            Item item = repo.getItemById(id);

            if (item.Quantity < 1)
            {
                return(new VendingMachineAPI.Models.MessageResult("{ \"message\" : \"SOLD OUT!!!\" }", Request));
            }

            if (money.CompareTo(item.Price) < 0)
            {
                decimal diff = item.Price - money;
                var     msg  = "{ \"message\" : \"Please deposit: $" + diff + " \" }";
                return(new VendingMachineAPI.Models.MessageResult(msg, Request));
            }

            item.Quantity = item.Quantity - 1;

            repo.updateItem(item);

            decimal changeAmount = money - item.Price;

            changeAmount = changeAmount * 100;
            int pennies = (int)changeAmount;

            var change = new Change(pennies);



            return(Json(change, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
예제 #2
0
        public IHttpActionResult getAllItems()
        {
            var         repo  = VendingMachineRepoFactory.GetRepository();
            List <Item> items = repo.getAllItems().ToList();

            return(Json(items, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }