public ActionResult Edit(int id) { if (_facade.IsValidFoodAdmin(Convert.ToInt32(Session["UserId"]), id)) { Food foodToUpdate = _foodContext.Get(id); var config = new MapperConfiguration(cfg => cfg.CreateMap <Food, FoodEditViewModel>()); var mapper = config.CreateMapper(); //Copy values FoodEditViewModel foodEdit = mapper.Map <FoodEditViewModel>(foodToUpdate); TempData["FoodId"] = id; TempData["RestaurantId"] = foodToUpdate.RestaurantId; return(View(foodEdit)); } return(RedirectToAction("Index", "RestaurantAdmin")); }
private IDataResult <Foods> CheckIfExist(int id) { var result = _foodRepository.Get(x => x.Id == id); if (result == null) { return(new ErrorDataResult <Foods>(Messages.FoodNotFound)); } return(new SuccessDataResult <Foods>(result)); }
public bool IsValidFoodAdmin(int userId, int foodId) { var restaurantId = _foodContext.Get(foodId).RestaurantId; if (restaurantId != null && IsValidRestaurantAdmin(userId, (int)restaurantId)) { return(true); } return(false); }
public async Task <IResult> UpdateAsync(FoodModel model) { var validation = await new UpdateFoodModelValidator().ValidateAsync(model); if (validation.Failed) { return(Result <long> .Fail(validation.Message)); } var food = _foodRepository.Get(model.Id); food.UpdateFood(model.Fat, model.Protine, model.Carbohydrate, model.IsVeg); await _foodRepository.UpdateAsync(model.Id, food); await _unitOfWork.SaveChangesAsync(); return(Result.Success()); }
public async Task <Food> FoodById(int Id) { Food getFood = await _foodRepo.Get(p => p.Id == Id); return(getFood); }
public Food Get(long id) { return(Repo.Get(id)); }
public Food Get(int id) { return(_foodRepository.Get(id)); }
public async Task <Food> GetById(string id) { return(_foodRepository.Get(id)); }