예제 #1
0
 public ActionResult CreateFermentable(FermentableViewModel vm)
 {
     try
     {
         using (var context = new Models.ModelsContext())
         {
             Fermentable newFermentable = new Fermentable();
             newFermentable.CoarseFineDiff = (float) (vm.CourseGrainYield - vm.Yield);
             newFermentable.Color = vm.Color;
             newFermentable.DiastaticPower = (float) vm.DiastaticPower;
             newFermentable.Name = vm.Name;
             newFermentable.Yield = (float) vm.Yield;
             newFermentable.IBUs = (float) vm.IBU;
             context.Fermentables.Add(newFermentable);
             context.SaveChanges();
             if (Request.IsAjaxRequest())
             {
                 return PartialView("~/Views/Ingredients/DisplayTemplates/FermentableViewModel.cshtml", vm);
             }
             else
             {
                 return RedirectToAction("Show", new {name = vm.Name, type = "fermentable"});
             }
         }
     }
     catch (Exception e)
     {
         return PartialView("~/Views/Ingredients/EditorTemplates/HopViewModel.cshtml", vm);
     }
 }
예제 #2
0
        public ActionResult Show(string name, string type = "hop")
        {
            using(var context = new Models.ModelsContext())
            {
                if (type == "hop")
                {
                    var hopModel = context.Hops.Find(name);

                    if (hopModel == null) return HttpNotFound();

                    var hopViewModel = new HopViewModel
                        {
                            Alpha = hopModel.Alpha,
                            Beta = hopModel.Beta,
                            Name = hopModel.Name,
                            Type = hopModel.HopType_Name,
                            PercentCaryophyllene = hopModel.Caryophyllene,
                            PercentCohumulone = hopModel.Cohumulone,
                            PercentHumulene = hopModel.Humulene,
                            PercentMyrcene = hopModel.Myrcene,
                            Form = hopModel.HopForm_Name,
                            Stability = hopModel.HSI,
                        };

                    return View(hopViewModel);
                }
                else if (type == "fermentable")
                {
                    var fermentableModel = context.Fermentables.Find(name);

                    if (fermentableModel == null) return HttpNotFound();

                    var fermentableViewModel = new FermentableViewModel
                        {
                            Color = fermentableModel.Color,
                            DiastaticPower = fermentableModel.DiastaticPower,
                            CourseGrainYield = fermentableModel.Yield + fermentableModel.CoarseFineDiff,
                            Name = fermentableModel.Name,
                            Yield = fermentableModel.Yield,
                            IBU = fermentableModel.IBUs,
                        };

                    return View(fermentableViewModel);
                }
                else
                {
                    return HttpNotFound();
                }
            }
        }