示例#1
0
        public ActionResult Edit(BrewBindingModel model, string id)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", "Brew", id));
            }
            try
            {
                BrewDomModel toEdit = new BrewDomModel
                {
                    Id          = Guid.Parse(id),
                    Name        = model.Name,
                    Description = model.Description,
                    RecipeId    = Guid.Parse(model.RecipeId)
                };

                this.manager.Edit(toEdit);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction("Edit", "Edit", id));
            }
        }
示例#2
0
        // GET: Brews/Create
        public ActionResult Create()
        {
            var model = new BrewBindingModel();

            var recipes = this.recipeManager.GetAll();

            SelectList listItems = new SelectList(recipes, "Id", "Name", model.RecipeId);

            model = new BrewBindingModel(new BrewDomModel(), listItems);
            return(View(model));
        }
示例#3
0
        // GET: Brews/Edit/5
        public ActionResult Edit(string id)
        {
            var brew  = this.manager.Find(Guid.Parse(id));
            var model = new BrewBindingModel();

            var recipes = this.recipeManager.GetAll();

            SelectList listItems = new SelectList(recipes, "Id", "Name", model.RecipeId);

            model = new BrewBindingModel(brew, listItems);

            return(View(model));
        }
示例#4
0
        public ActionResult Create(BrewBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Create)));
            }
            try
            {
                var brew = new BrewDomModel
                {
                    Name        = model.Name,
                    Description = model.Description,
                    RecipeId    = Guid.Parse(model.RecipeId),
                };

                this.manager.Add(brew);
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction(nameof(Create)));
            }
        }