public IActionResult NewCheese(Cheese newCheese) { // Add the new cheese to my existing cheeses CheeseData.Add(newCheese); return(Redirect("/Cheese")); }
public IActionResult NewCheese(string name, string description) { // Add the new cheese to my existing cheeses CheeseData.Add(new Cheese(name, description)); return(Redirect("/")); }
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")); }
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")); }
public IActionResult NewCheese(Cheese newCheese) { //add new cheese to list //Cheese newCheese = new Cheese(name, desc); CheeseData.Add(newCheese); return(Redirect("/Cheese")); }
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"); }
public IActionResult NewCheese(Cheese newCheese) { /* Cheese newCheese = new Cheese * { * Name = name, * Description = description * }; */ CheeseData.Add(newCheese); return(Redirect("/Cheese")); }
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")); }
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")); }
public IActionResult Add(AddCheeseViewModel addCheeseViewModel) { if (ModelState.IsValid) { Cheese newCheese = addCheeseViewModel.CreateCheese(); CheeseData.Add(newCheese); return(Redirect("/Cheese")); } return(View(addCheeseViewModel)); }
// 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)); }
[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)); }
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)); }
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)); }
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")); }
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)); }
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)); }
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)); }
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)); }
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")); }
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))); }
public IActionResult NewCheese(Cheese cheese) { CheeseData.Add(cheese); return(Redirect("/Cheese")); }
public IActionResult Add(Cheese cheese) { CheeseData.Add(cheese); return(Redirect("Index")); }