public ActionResult Delete(int id) { var meal = _mealRepository.GetMealById(id); _mealRepository.DeleteMeal(meal); return(RedirectToAction(nameof(Index))); }
public void DeleteMeal(Meal meal) { foreach (Ingredient ingredient in meal.Ingredients) { _ingredientRepository.DeleteIngredient(ingredient.Id); } _mealRepository.DeleteMeal(meal.Id); }
public async Task <IActionResult> DeleteMeal(int mealId) { var meal = await MealRepository.DeleteMeal(mealId); if (meal == null) { return(BadRequest()); } return(Accepted()); }
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); }
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")); }
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")); } }
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); } }
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); }
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); }