コード例 #1
0
ファイル: IngredientsController.cs プロジェクト: nsipid/Brew
        public ActionResult CreateHop(HopViewModel vm)
        {
            using (var context = new Models.ModelsContext())
            {
                try
                {
                    Hop newHop = new Hop();

                    newHop.Name = vm.Name;
                    newHop.Alpha = (float) vm.Alpha;
                    newHop.Beta = (float) vm.Beta;
                    newHop.Caryophyllene = (float) vm.PercentCaryophyllene;
                    newHop.Cohumulone = (float) vm.PercentCohumulone;
                    newHop.HSI = (float) vm.Stability;
                    newHop.Humulene = (float) vm.PercentHumulene;

                    context.Hops.Add(newHop);
                    context.SaveChanges();
                    if (Request.IsAjaxRequest())
                    {
                        return PartialView("~/Views/Ingredients/DisplayTemplates/HopViewModel.cshtml", vm);
                    }
                    else
                    {
                        return RedirectToAction("Show", new {name = vm.Name, type = "hop"});
                    }
                }
                catch (Exception e)
                {
                    return PartialView("~/Views/Ingredients/EditorTemplates/HopViewModel.cshtml", vm);
                }
            }
        }
コード例 #2
0
ファイル: IngredientsController.cs プロジェクト: nsipid/Brew
        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();
                }
            }
        }