Ejemplo n.º 1
0
        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"));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 5
0
        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));
 }
Ejemplo n.º 7
0
 public Food Get(int id)
 {
     return(_foodRepository.Get(id));
 }
Ejemplo n.º 8
0
 public async Task <Food> GetById(string id)
 {
     return(_foodRepository.Get(id));
 }