Пример #1
0
        public ActionResult Create(int recipeId)
        {
            var recipe = RecipeService.GetRecipe(recipeId);
            var model = new BrewViewModel()
                            {
                                RecipeId = recipeId,
                                Title = recipe.Title,
                                Status = "Created",
                                Annotations = string.Format("> This brew is based on the recipe [{0}]({1})", recipe.Title, Url.Action("Details", "Recipes", new { id = recipeId }))
                            };
            model.Statuses.First().Selected = true;

            return View(model);
        }
Пример #2
0
        public ActionResult Create_Post(int recipeId, BrewViewModel postedModel)
        {
            if (ModelState.IsValid)
            {
                var brew = BrewService.CreateBrew(User.Identity.Name, recipeId, postedModel.Title, postedModel.Annotations, (BrewStatus)Enum.Parse(typeof(BrewStatus), postedModel.Status));

                if (postedModel.IsPublic)
                {
                    BrewService.MakePublic(brew.Id);
                }
                else
                {
                    BrewService.MakePrivate(brew.Id);
                }

                return RedirectToAction("Details", new { id = brew.Id });
            }

            postedModel.Statuses.First(s => s.Text == postedModel.Status).Selected = true;

            return View(postedModel);
        }
Пример #3
0
        public ActionResult Link_Post(int id, BrewViewModel postedModel)
        {
            int brewId = id;
            if (!string.IsNullOrEmpty(postedModel.SensorId))
            {
                BrewService.LinkSensor(brewId, postedModel.SensorId);
            }
            else
            {
                var brew = BrewService.GetBrew(id);
                BrewService.UnlinkSensor(brewId, brew.SensorId);
            }

            return RedirectToAction("Details", new { id = brewId });
        }