public void Add(TreatmentRatioModelView model)
        {
            using (var ratio = new TreatmentRatioRepository())
            {
                string percentage = _percentage.GetAll()
                                    .ToList()
                                    .Find(x => x.TreatmentPercentageId == model.TreatmentPercentageId)
                                    .Percentage;
                int perc = percentage.Length;

                double ingredient =
                    _ingredients.GetAll().ToList().Find(x => x.IngredientId == model.IngredientId).TotalMass;
                decimal treatPriceTot =
                    _ingredients.GetAll().ToList().Find(x => x.IngredientId == model.IngredientId).TotalPrice;
                double mass = (Convert.ToDouble(percentage.Substring(0, perc - 2)) / 100) * ingredient;

                var treat = new TreatmentRatio
                {
                    TreatmentRatioId      = model.TreatmentRatioId,
                    IngredientId          = model.IngredientId,
                    TreatmentPercentageId = model.TreatmentPercentageId,
                    TotalMass             = mass,
                    TreatPrice            = treatPriceTot * (Convert.ToDecimal(percentage.Substring(0, perc - 2)) / 100),
                    Tid = model.Tid
                };
                ratio.Insert(treat);
                var stock = _ingredients.GetAll().ToList().Find(x => x.IngredientId == model.IngredientId);
                if (stock != null)
                {
                    double massLeff  = stock.TotalMass - mass;
                    double massRatio = massLeff / stock.IngredientMass;
                    int    index     = massRatio.ToString(CultureInfo.InvariantCulture).IndexOf('.');

                    int number = 0;
                    if (index > 0)
                    {
                        number = (Convert.ToInt16(massRatio.ToString(CultureInfo.InvariantCulture).Substring(0, index)) + 1);
                        stock.NumIngredients = number;
                    }
                    else
                    {
                        number = Convert.ToInt16(massRatio.ToString(CultureInfo.InvariantCulture));
                        stock.NumIngredients = number;
                    }
                    stock.TotalMass = Math.Round(massLeff, 0);
                    _ingredients.Update(stock);
                }
            }
        }
Esempio n. 2
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 }));
        }
Esempio n. 3
0
        internal object Update(int id, Ingredient updatedIngredient)
        {
            Ingredient original = GetById(id);

            updatedIngredient.Id    = id;
            updatedIngredient.Title = updatedIngredient.Title == null ? original.Title : updatedIngredient.Title;
            updatedIngredient.Cal   = updatedIngredient.Cal == null ? original.Cal : updatedIngredient.Cal;
            if (_repo.Update(updatedIngredient))
            {
                return(updatedIngredient);
            }
            throw new Exception("oop that Ingredient dont fly homie");
        }
        public IActionResult Update(string id, Ingredient ingredientIn)
        {
            var ingredient = _ingredientsRepository.Get(id);

            if (ingredient == null)
            {
                return(NotFound());
            }

            _ingredientsRepository.Update(id, ingredientIn);

            return(NoContent());
        }
Esempio n. 5
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);
         }
     }
 }
Esempio n. 6
0
 public void Update(Ingredient ingredient)
 {
     _repo.Update(ingredient);
 }