Пример #1
0
        public ActionResult Delete(int id)
        {
            var meal = _mealRepository.GetMealById(id);

            _mealRepository.DeleteMeal(meal);

            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        public void DeleteMeal(Meal meal)
        {
            foreach (Ingredient ingredient in meal.Ingredients)
            {
                _ingredientRepository.DeleteIngredient(ingredient.Id);
            }

            _mealRepository.DeleteMeal(meal.Id);
        }
Пример #3
0
        public async Task <IActionResult> DeleteMeal(int mealId)
        {
            var meal = await MealRepository.DeleteMeal(mealId);

            if (meal == null)
            {
                return(BadRequest());
            }

            return(Accepted());
        }
Пример #4
0
        public async Task RemoveMeal(int mealId)
        {
            var meal = await _mealRepository.GetMeal(mealId);

            if (meal == null)
            {
                _logger.LogInformation("Error while deleting a meal");
                throw new MealNotFoundException();
            }
            await _mealRepository.DeleteMeal(mealId);
        }
Пример #5
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         Meal meal = mealRepository.GetMealByID(id);
         mealRepository.DeleteMeal(id);
     }
     catch (DataException)
     {
         return(RedirectToAction("Delete",
                                 new Microsoft.AspNetCore.Routing.RouteValueDictionary
         {
             { "id", id },
             { "saveChangesError", true }
         }));
     }
     return(RedirectToAction("Index"));
 }
Пример #6
0
        public IActionResult DeleteMeal(MealButtonViewModel MealButtonViewModel)
        {
            Meal Meal = MealRepository.Meals.Where(e => e.ID == MealButtonViewModel.MealID).FirstOrDefault();

            if (Meal.Eaters.Count != 0)
            {
                return(View("Error"));
            }
            if (User != null && !Meal.Cook.Id.Equals(User.FindFirstValue(ClaimTypes.NameIdentifier)))
            {
                return(View("Error"));
            }
            if (MealRepository.DeleteMeal(MealButtonViewModel.MealID))
            {
                return(Redirect("/Meal"));
            }
            else
            {
                return(View("Error"));
            }
        }
Пример #7
0
        public async Task ChooseMeals(Guid id, IEnumerable <Dish> dishes)
        {
            await EnsureGuestExists(id);

            var meals = await GetMeals(id);

            var toDelete = meals.Where(w => !dishes.Any(a => a.Id == w.DishId));
            var toCreate = dishes.Where(w => !meals.Any(a => a.DishId == w.Id)).Select(s => new Meal {
                GuestId = id, DishId = s.Id
            });

            foreach (var meal in toDelete)
            {
                await _mealRepository.DeleteMeal(meal.Id);
            }

            foreach (var meal in toCreate)
            {
                await _mealRepository.CreateMeal(meal);
            }
        }
Пример #8
0
        async public Task <Dictionary <ServiceDictionaryKey, object> > TryDeleteMeal(HttpRequest request)
        {
            Dictionary <ServiceDictionaryKey, object> dictionary = new Dictionary <ServiceDictionaryKey, object>();
            int patientId = 0;
            int mealId    = 0;

            try
            {
                //TODO haal patient id op een coole manier op
                mealId    = Convert.ToInt32(request.Query["mealId"].ToString());
                patientId = Convert.ToInt32(request.Query["patientId"].ToString());
            }
            catch (Exception ex)
            {
                dictionary.AddErrorMessage(ServiceDictionaryKey.ERROR, ex, FeedbackHandler);
            }
            try
            {
                bool succes = await _mealRepository.DeleteMeal(patientId, mealId);

                if (!succes)
                {
                    dictionary.Add(ServiceDictionaryKey.ERROR, "No rows affected. Does the meal exist?");
                    dictionary.Add(ServiceDictionaryKey.HTTPSTATUSCODE, HttpStatusCode.NotFound);
                }
                else
                {
                    dictionary.Add(ServiceDictionaryKey.VALUE, "Meal deleted");
                    dictionary.Add(ServiceDictionaryKey.HTTPSTATUSCODE, HttpStatusCode.OK);
                }
            }
            catch (Exception ex)
            {
                dictionary.AddErrorMessage(ServiceDictionaryKey.ERROR, ex, FeedbackHandler);
            }
            return(dictionary);
        }
Пример #9
0
        public IActionResult Delete(int mealId)
        {
            // Get meal
            Meal meal = mealRepository.GetMeal(mealId);
            // Get student
            Student student = studentRepository.GetStudent(GetUserId());

            // Check if student is allowed to delete meal
            DomainMethodResult result = meal.AllowedToEdit(student);

            // Check for result
            if (result.WasSuccessful)
            {
                mealRepository.DeleteMeal(meal);
                TempData["success"] = "Maaltijd succesvol verwijderd";
            }
            else
            {
                TempData["error"] = result.Message;
            }

            // Render main view
            return(RedirectToAction("List"));
        }
        public void DeleteMeal(MealDTO mealDTO)
        {
            var meal = _mealMapper.GetMealFromMealDTO(mealDTO);

            _mealRepository.DeleteMeal(meal);
        }