コード例 #1
0
ファイル: ItemController.cs プロジェクト: rodolfoleal/Gratify
        public async Task <IActionResult> DeleteItem(int listId, int itemId)
        {
            var wishList = await _wishListBusiness.Query().Include(w => w.Items).FirstOrDefaultAsync(w => w.Id == listId);

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

            if (wishList.Items.FirstOrDefault(i => i.Id == itemId) == null)
            {
                return(BadRequest(@"List does not contains Item with id {itemId}"));
            }

            var itemEntity = await _itemBusiness.GetAsync(itemId);

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

            if (await _itemBusiness.RemoveAsync(itemEntity) == false)
            {
                return(StatusCode(500));
            }

            return(NoContent());
        }