Beispiel #1
0
 public ActionResult Add(TreatmentRatioModelView model)
 {
     if (ModelState.IsValid)
     {
         ViewBag.IngredientId          = new SelectList(_ingredients.GetAll(), "IngredientId", "IngredientName");
         ViewBag.TreatmentPercentageId = new SelectList(_percentage.GetPercentage(), "TreatmentPercentageId", "Percentage");
         _ratio.Add(model);
         return(RedirectToAction("GetAll"));
     }
     return(View(model));
 }
        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);
                }
            }
        }
 public void Update(TreatmentRatioModelView model)
 {
     throw new NotImplementedException();
 }