コード例 #1
0
        public IHttpActionResult Post([FromBody] ShoppingListItem item, Guid familyId)
        {
            if (IsDefault(item))
            {
                return(BadRequest());
            }
            //TODO: authenticate whether use has access to family shopping list
            var shopItem = _shopService.GetShoppingListItemDetailsByName(familyId, item.Name);

            if (shopItem != null)
            {
                return(BadRequest("The item is already in the shoppinglist, try updating the existing item."));
            }
            _shopService.AddItemToFamilyShoppingList(familyId, item);
            var returnItem = _shopService.GetShoppingListItemDetailsByName(familyId, item.Name);

            return(Created(WebConfigurationManager.AppSettings["baseUrl"] + $"api/shoppinglists/{familyId}/items/{returnItem.Id}", returnItem));
        }