Exemple #1
0
        public IActionResult Add(string txtItem)
        {
            if (!string.IsNullOrWhiteSpace(txtItem))
            {
                _data.AddItem(txtItem);
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult <IEnumerable <string> > AddItem([FromBody] AddItem item)
        {
            int id = _data.AddItem(item.Item);

            if (id > 0)
            {
                return(Ok(GetShoppingItems()));
            }
            else
            {
                return(BadRequest($"Unable to add item: {item.Item}"));
            }
        }
        public ActionResult <ShoppingItem> CreateItem([FromRoute] Guid listId, [FromBody] ShoppingItemRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var shoppingItem = new ShoppingItem
            {
                Id          = Guid.NewGuid(),
                Description = request.Description,
                Checked     = request.Checked
            };

            var res = _service.AddItem(listId, shoppingItem);

            if (res == null)
            {
                return(NotFound());
            }

            return(res);
        }