コード例 #1
0
        public IActionResult Add(string txtItem)
        {
            if (!string.IsNullOrWhiteSpace(txtItem))
            {
                _data.AddItem(txtItem);
            }

            return(RedirectToAction("Index"));
        }
コード例 #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}"));
            }
        }
コード例 #3
0
        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);
        }