コード例 #1
0
        public IHttpActionResult DeleteList(int id)
        {
            try
            {
                FoodList singleFoodList = _foodListRepository.GetSingle(x => x.Id == id, "Foods");

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

                if (singleFoodList.UserId != CurrentUserId)
                {
                    return(StatusCode(HttpStatusCode.Forbidden));
                }

                _foodListRepository.Delete(singleFoodList);
                int save = _foodListRepository.Save();

                if (save > 0)
                {
                    return(StatusCode(HttpStatusCode.NoContent));
                }

                return(BadRequest());
            }
            catch (Exception exception)
            {
                return(InternalServerError(exception));
            }
        }
コード例 #2
0
        public IActionResult DeleteList(Guid id)
        {
            FoodList singleFoodList = _foodListRepository.GetSingle(id, true);

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

            if (singleFoodList.UserId != _userManager.GetUserId(HttpContext.User))
            {
                return(new StatusCodeResult((int)HttpStatusCode.Forbidden));
            }

            _foodListRepository.Delete(singleFoodList.Id);

            if (_foodListRepository.Save())
            {
                return(NoContent());
            }

            return(BadRequest());
        }