예제 #1
0
        public IActionResult NewCheese(Cheese newCheese)
        {
            // Add the new cheese to my existing cheeses
            CheeseData.Add(newCheese);

            return(Redirect("/Cheese"));
        }
예제 #2
0
        public IActionResult NewCheese(string name, string description)
        {
            // Add the new cheese to my existing cheeses
            CheeseData.Add(new Cheese(name, description));

            return(Redirect("/"));
        }
예제 #3
0
        public IActionResult Add(AddCheeseViewModel addedCheese)
        {
            if (!(ModelState.IsValid))
            {
                return(View(addedCheese));
            }

            if ((String.IsNullOrEmpty(addedCheese.Name)) || !(IsAlpha(addedCheese.Name)))
            {
                string error = "The cheese name is required and must be alphabetic.";
                ViewBag.error = error;

                return(View(addedCheese));
            }

            Cheese newCheese = new Cheese
            {
                Name        = addedCheese.Name,
                Description = addedCheese.Description,
                Type        = addedCheese.Type
            };

            CheeseData.Add(newCheese);

            return(Redirect("/Cheese"));
        }
예제 #4
0
        public IActionResult NewCheese(string name, string description)
        {
            ViewBag.error = errorCheck;

            if (name == " ")
            {
                errorCheck = true;
                return(Redirect("/Cheese/Add"));
            }
            foreach (char letter in name)
            {
                if (String.IsNullOrEmpty(name) || !ValidChars.Contains(char.ToLower(letter)))
                {
                    errorCheck = true;
                    return(Redirect("/Cheese/Add"));
                }
            }

            Cheese newCheese = new Cheese
            {
                Name        = name,
                Description = description
            };

            CheeseData.Add(newCheese);
            errorCheck = false;

            return(Redirect("/Cheese"));
        }
예제 #5
0
        public IActionResult NewCheese(Cheese newCheese)
        {
            //add new cheese to list
            //Cheese newCheese = new Cheese(name, desc);
            CheeseData.Add(newCheese);

            return(Redirect("/Cheese"));
        }
예제 #6
0
        public IActionResult NewCheese(Cheese newCheese)
        {
            // Add the new cheese to my existing cheeses
            //Cheeses.Add(new Cheese(name, description));//this is how you add a new cheese based on the constructor

            CheeseData.Add(newCheese);

            return Redirect("/Cheese");
        }
예제 #7
0
 public IActionResult NewCheese(Cheese newCheese)
 {
     /* Cheese newCheese = new Cheese
      * {
      *  Name = name,
      *  Description = description
      * }; */
     CheeseData.Add(newCheese);
     return(Redirect("/Cheese"));
 }
예제 #8
0
        public IActionResult NewCheese(Cheese newCheese)
        {
            ViewBag.error = "";

            // add new cheese to static class list
            CheeseData.Add(newCheese);

            // go back to the list of cheeses
            return(Redirect("/cheese"));
        }
예제 #9
0
        public IActionResult NewCheese(Cheese newCheese)
        {
            //Cheese newCheese = new Cheese();;
            //newCheese.Name = Request.get("name");
            //newCheeseDescription = Request.get("description")
            //Add new cheese to existing cheeses.
            CheeseData.Add(newCheese);

            return(Redirect("/Cheese"));
        }
예제 #10
0
 public IActionResult Add(AddCheeseViewModel addCheeseViewModel)
 {
     if (ModelState.IsValid)
     {
         Cheese newCheese = addCheeseViewModel.CreateCheese();
         CheeseData.Add(newCheese);
         return(Redirect("/Cheese"));
     }
     return(View(addCheeseViewModel));
 }
예제 #11
0
        // Model binding: you can pass form data through to an object's constructor and if the input names match the the parameters in the constructor, the framework will automatically create a new object of that type. I prefer the explicit workflow as it allows me to visually track what parameters are being passed, stage by stage.
        public IActionResult Add(AddCheeseViewModel addCheeseViewModel)
        {
            if (ModelState.IsValid)
            {
                Cheese newCheese = addCheeseViewModel.CreateCheese(addCheeseViewModel);

                //add the new cheese to my existing cheeses
                CheeseData.Add(newCheese);
                return(Redirect("/cheese"));
            }

            return(View(addCheeseViewModel));
        }
예제 #12
0
        [Route("/Cheese/Add")] //specify where the form lives
                               // our form has no action method,
                               //so we need this here
        public IActionResult NewCheese(string name, string description)
        {
            //accessing the empty constructor i created in the Cheese model class
            Cheese newCheese = new Cheese
            {
                Description = description,
                Name        = name
            };

            //Add the new cheese to my existing cheeses by passing it to the Add method
            CheeseData.Add(newCheese);
            return(Redirect("/Cheese"));
        }
        public IActionResult Edit(EditCheeseViewModel editCheeseViewModel)
        {
            if (ModelState.IsValid)
            {
                CheeseData.Remove(editCheeseViewModel.CheeseId);

                Cheese cheese = editCheeseViewModel.CreateCheese();

                CheeseData.Add(cheese);

                return(Redirect("/Cheese"));
            }

            return(View(editCheeseViewModel));
        }
예제 #14
0
 public IActionResult Add(AddCheeseViewModel addCheeseViewModel)
 {
     if (ModelState.IsValid)
     {
         Cheese newCheese = new Cheese
         {
             Name        = addCheeseViewModel.Name,
             Description = addCheeseViewModel.Description,
             Type        = addCheeseViewModel.Type
         };
         CheeseData.Add(newCheese);
         return(Redirect("/Cheese"));
     }
     return(View(addCheeseViewModel));
 }
예제 #15
0
 public IActionResult Add(AddCheeseViewModel addCheeseViewModel)
 {
     // Add the new cheese to my existing cheeses
     if (ModelState.IsValid)
     {
         Cheese newCheese = new Cheese
         {
             Name        = addCheeseViewModel.Name,
             Description = addCheeseViewModel.Description
         };
         CheeseData.Add(newCheese);
         return(Redirect("/Cheese"));
     }
     return(View(addCheeseViewModel));
 }
예제 #16
0
        public IActionResult NewCheese(AddCheeseViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Add", viewModel));
            }

            // add new cheese to static class list
            Cheese newCheese = viewModel.CreateCheese();

            CheeseData.Add(newCheese);

            // go back to the list of cheeses
            return(Redirect("/cheese"));
        }
예제 #17
0
        public IActionResult Add(AddCheeseViewModel addCheeseViewModel)
        {
            if (ModelState.IsValid)
            {
                //Add the new cheese to my exsiting list
                Cheese newCheese = new Cheese
                {
                    Name        = addCheeseViewModel.Name,
                    Description = addCheeseViewModel.Description,
                    Taste       = addCheeseViewModel.Taste,
                    Type        = addCheeseViewModel.Type
                };
                CheeseData.Add(newCheese);
                return(Redirect("/Cheese"));
            }

            return(View(addCheeseViewModel));
        }
예제 #18
0
        public IActionResult Add(AddCheeseViewModel addCheeseViewModel) //here i recieve an addcheese viewmodel object
        {
            if (ModelState.IsValid)                                     //this checks if the form state that is passed to the controller is valid. It's gotta have data
            {
                // Add the new cheese to my existing cheeses
                Cheese newCheese = new Cheese
                {
                    Name        = addCheeseViewModel.Name,
                    Description = addCheeseViewModel.Description,
                    Type        = addCheeseViewModel.Type
                };

                CheeseData.Add(newCheese);

                return(Redirect("/Cheese"));
            }
            return(View(addCheeseViewModel));
        }
예제 #19
0
        public IActionResult Add(EditCheeseViewModel cheeseListViewModel)
        {
            if (ModelState.IsValid)
            {
                Cheese newCheese = new Cheese
                {
                    Name        = cheeseListViewModel.Name,
                    Description = cheeseListViewModel.Description,
                    Type        = cheeseListViewModel.Type
                };

                // Add the new cheese to my existing cheeses
                CheeseData.Add(newCheese);

                return(Redirect("/Cheese"));
            }
            return(View(cheeseListViewModel));
        }
예제 #20
0
        public IActionResult Add(AddCheeseViewModel addCheeseViewModel)
        {
            if (ModelState.IsValid)
            {
                // Add the new cheese to my existing cheeses
                //CheeseData.Add(new Cheese{
                //    Name = addCheeseViewModel.Name,
                //    Description = addCheeseViewModel.Description,
                //    Type = addCheeseViewModel.Type,
                //    Rating = addCheeseViewModel.Rating
                //});

                /*context.Cheeses.Add(addCheeseViewModel.CreateCheese());
                 * context.SaveChanges();*/
                CheeseData.Add(addCheeseViewModel.CreateCheese());

                return(Redirect("/"));
            }

            return(View(addCheeseViewModel));
        }
예제 #21
0
        public IActionResult NewCheese(Cheese newCheese)
        //public IActionResult NewCheese(string name, string description = "")
        {
            /* Framework using Model Binding and creates and populate data qith the default constructor
             *
             * Cheese newCheese = new Cheese();
             * newCheese.Name = Request.get("name");
             * newCheese.Description = Request.get("description");
             *
             *
             * // Constructor Kind Of
             * /*
             * Cheese newCheese = new Cheese() {
             *  Description = description,
             *  Name = name
             * };*/

            // Add the new cheese to my existing cheeses
            CheeseData.Add(newCheese);

            return(Redirect("/Cheese"));
        }
예제 #22
0
        public IActionResult NewCheese(Cheese newCheese)
        {
            //Add the new cheese to my existing cheeses

            /*Model binding means we don't have to create a new cheese like this. But you have to
             * have a default constructor in the model for model binding to work
             * Cheese newCheese = new Cheese
             * {
             *  Description = description,
             *  Name = name
             * };
             */

            CheeseData.Add(newCheese);

            /*Another way:
             * Cheese newCheese = new Cheese();
             * newCheese.Description = description;
             * newCheese.Name = name;
             */

            return(RedirectToAction(actionName: nameof(Index)));
        }
예제 #23
0
 public IActionResult NewCheese(Cheese cheese)
 {
     CheeseData.Add(cheese);
     return(Redirect("/Cheese"));
 }
예제 #24
0
 public IActionResult Add(Cheese cheese)
 {
     CheeseData.Add(cheese);
     return(Redirect("Index"));
 }