public async Task <MealResponse> Delete(Meal meal) { mealRepository.Delete(meal); await unitOfWork.Complete(); return(new MealResponse(true, null)); }
public async Task <Result> Handle(DeleteMealCommand request, CancellationToken cancellationToken) { if (request.MealId == 0) { throw new GroceryException("INVALID_MEALID"); } await _repository.Delete(request.MealId); return(Result.Ok()); }
public ActionResult Delete(int id) { try { repository.Delete(id); return(RedirectToAction("Index")); } catch { return(View()); } }
//User deletes meal public async Task DeleteMealAsync(UserModel user, int mealId) { if (user.Position == (int)UserPosition.HasNotHome) { CustomException errors = new CustomException((int)HttpStatusCode.BadRequest); errors.AddError("Home Not Exist", "User is not member of a home"); errors.Throw(); } user = await _userRepository.GetByIdAsync(user.Id, true); HomeModel home = await _homeRepository.GetByIdAsync(user.Home.Id, true); MealModel meal = await _mealRepository.GetHomeMealByIdAsync(mealId, true); if (meal == null) { CustomException errors = new CustomException((int)HttpStatusCode.BadRequest); errors.AddError("Meal Not Exist", "This meal has not exist"); errors.Throw(); } if (meal.Home.Id != home.Id) { CustomException errors = new CustomException((int)HttpStatusCode.BadRequest); errors.AddError("Meal Not Related Home", "This meal is not related with user home"); errors.Throw(); } //Finds and deletes all related menu meals List <MenuMealModel> menuMeals = await _menuMealRepository.GetAllMenuMealsByMealIdAsync(mealId); foreach (var menuMeal in menuMeals) { _menuMealRepository.Delete(menuMeal); } foreach (var friend in home.Users) { FCMModel fcm = new FCMModel(friend.DeviceId, type: "DeleteMeal"); fcm.data.Add("MealId", mealId); await _fcmService.SendFCMAsync(fcm); } _mealRepository.Delete(meal); }
public IActionResult Delete(MealButtonViewModel mealButtonViewModel) { Meal meal = _mealRepository.Meals.Where(m => m.Id == mealButtonViewModel.MealId).FirstOrDefault(); IActionResult actionResult = View(mealButtonViewModel); if (!ModelState.IsValid || meal?.Guests?.Count != 0 || (!meal?.Cook?.Id.Equals(User?.FindFirstValue(ClaimTypes.NameIdentifier))) == true) { actionResult = View("Error"); } else { _mealRepository.Delete(mealButtonViewModel.MealId); actionResult = Redirect("/Meal"); } return(actionResult); }
public JsonResult Delete(string stringMealId) { int intMealId = int.MinValue; if (Int32.TryParse(stringMealId, out intMealId)) { if (_mealRepository.Delete(intMealId)) { Response.StatusCode = (int)HttpStatusCode.OK; return(new JsonResult { Data = new { message = "Udało się usunąc danie :)" } }); } Response.StatusCode = (int)HttpStatusCode.NotFound; return(new JsonResult()); } Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(new JsonResult()); }
public async Task Delete(int id) { await _mealRepository.Delete(id); }
public void RemoveMeal(Guid mealId) { var meal = _mealRepository.GetById(mealId); _mealRepository.Delete(meal); }
public bool Execute() { return(mealRepository.Delete(Id)); }
public void Delete(int id) { _mealRepository.Delete(id); _ingredientRepository.DeleteMealIngredients(id); _allergenRepository.DeleteMealAllergens(id); }
public ActionResult Delete(int id) { _mealRepository.Delete(_mealRepository.FindById(id)); return(Ok(_mealRepository.Save())); }
public void Delete(IMealModel mealModel) { //throw new NotImplementedException(); _mealRepository.Delete(mealModel); }