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)); } }
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()); }