Пример #1
0
        public ActionResult Edit(EditIngredientViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!User.IsInRole("Administrator"))
            {
                return(View("Error"));
            }

            var ingredientEntity = _ingredientsRepository.GetById(viewModel.Id);

            ingredientEntity.Name = viewModel.Name;

            TryValidateModel(ingredientEntity);

            if (!ModelState.IsValid)
            {
                this.AddNotification("Грешка при запазване на промените: Името на съставката не е валидно.", NotificationType.ERROR);
                return(RedirectToAction("Index", new { page = viewModel.CurrentPage, searchText = viewModel.SearchText }));
            }

            _ingredientsRepository.Update(ingredientEntity);

            if (!_ingredientsRepository.Save())
            {
                this.AddNotification("Грешка при запазване на промените: Името на съставката не е валидно.", NotificationType.ERROR);
                return(RedirectToAction("Index", new { page = viewModel.CurrentPage, searchText = viewModel.SearchText }));
            }

            this.AddNotification("Съставката е променена.", NotificationType.SUCCESS);
            return(RedirectToAction("Index", new { page = viewModel.CurrentPage, searchText = viewModel.SearchText }));
        }
Пример #2
0
        public Ingredient Get(int Id)
        {
            Ingredient exists = _repo.GetById(Id);

            if (exists == null)
            {
                throw new Exception("Invalid ingredient mi amigo");
            }
            return(exists);
        }
Пример #3
0
        internal Ingredient GetById(int id)
        {
            var data = _repo.GetById(id);

            if (data == null)
            {
                throw new Exception("Invalid Id");
            }
            return(data);
        }
Пример #4
0
        internal Ingredient GetById(int id)
        {
            Ingredient ingredient = _repo.GetById(id);

            if (ingredient == null)
            {
                throw new Exception("Invalid Ingredient Id");
            }
            return(ingredient);
        }
Пример #5
0
 public void Delete(int id)
 {
     using (var ingredient = new IngredientsRepository())
     {
         TreatmentIngredients treat = ingredient.GetById(id);
         if (treat != null)
         {
             ingredient.Delete(treat);
         }
     }
 }
Пример #6
0
 public void Update(IngredientsViewPar model)
 {
     using (var ingredient = new IngredientsRepository())
     {
         TreatmentIngredients treat = ingredient.GetById(model.IngredientId);
         if (treat != null)
         {
             treat.IngredientId    = model.IngredientId;
             treat.IngredientName  = model.IngredientName;
             treat.NumIngredients  = model.NumIngredients;
             treat.IngredientMass  = model.IngredientMass;
             treat.Ingredientprice = model.Ingredientprice;
             treat.TotalPrice      = model.Ingredientprice * model.NumIngredients;
             treat.TotalMass       = model.IngredientMass * model.NumIngredients;
             ingredient.Update(treat);
         }
     }
 }
Пример #7
0
 public IngredientsViewPar GetById(int id)
 {
     using (var ingredient = new IngredientsRepository())
     {
         TreatmentIngredients treat = ingredient.GetById(id);
         var ingredientview         = new IngredientsViewPar();
         if (treat != null)
         {
             ingredientview.IngredientId    = treat.IngredientId;
             ingredientview.IngredientName  = treat.IngredientName;
             ingredientview.NumIngredients  = treat.NumIngredients;
             ingredientview.IngredientMass  = treat.IngredientMass;
             ingredientview.Ingredientprice = treat.Ingredientprice;
             ingredientview.TotalPrice      = treat.TotalPrice;
             ingredientview.TotalMass       = treat.TotalMass;
         }
         return(ingredientview);
     }
 }
Пример #8
0
 public List <Ingredient> GetById(int id)
 {
     return(_repo.GetById(id));
 }
Пример #9
0
 public Ingredient GetById(int id)
 {
     return(_repo.GetById(id));
 }