Пример #1
0
        public async Task <IActionResult> DeleteMeal(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var userId            = userService.GetCurrentUserId(HttpContext);
            var findMealsResponse = await mealService.GetUserMeals(userId).ConfigureAwait(false);

            if (!findMealsResponse.IsSuccess)
            {
                return(BadRequest(findMealsResponse.Message));
            }

            var meal = findMealsResponse.MealsFound.Where(m => m.ID == id).SingleOrDefault();

            if (meal == null)
            {
                return(BadRequest("Meal doesn't exist"));
            }

            var response = await mealService.Delete(meal).ConfigureAwait(false);

            if (!response.IsSuccess)
            {
                return(BadRequest(response.Message));
            }

            return(NoContent());
        }
Пример #2
0
        public IActionResult Delete(int id)
        {
            var result = mealManager.Delete(id);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public ActionResult Delete(int id)
        {
            var meal = _mealService.GetById(id);

            if (System.IO.File.Exists(Server.MapPath(meal.Image)))
            {
                System.IO.File.Delete(Server.MapPath(meal.Image));
            }
            _mealService.Delete(meal);
            return(RedirectToAction("Index"));
        }
Пример #4
0
 public IActionResult Delete([FromBody] Meal model)
 {
     _mealService.Delete(model);
     return(Ok());
 }
Пример #5
0
 public IActionResult Delete([FromRoute] int id)
 {
     _mealService.Delete(id);
     return(Ok());
 }