public ViewResult MakeBooking(Appointment appt) { //if (string.IsNullOrEmpty(appt.ClientName)) //{ // ModelState.AddModelError("ClientName", "Please enter a name"); //} //if (ModelState.IsValidField("Date") && DateTime.Now > appt.Date) //{ // ModelState.AddModelError("Date", "Please enter a date in the fu"); //} //if (!appt.TermsAccepted) //{ // ModelState.AddModelError("TermsAccepted", "You must accept the terms"); //} //if (ModelState.IsValidField("ClientName") && ModelState.IsValidField("Date") // && appt.ClientName == "Joe" && appt.Date.DayOfWeek == DayOfWeek.Monday) //{ // ModelState.AddModelError("", "Joe cannot book on Mondays"); //} if (ModelState.IsValid) { // store repository code goes here return View("Completed", appt); } else { return View(); } }
public ActionResult MakeBooking(Appointment appt) { //if (string.IsNullOrEmpty(appt.ClientName)) //{ // ModelState.AddModelError("ClientName", "Please enter your name"); //} //if (ModelState.IsValidField("Date") && DateTime.Now > appt.Date) //{ // ModelState.AddModelError("Date", "Please enter a date in the future"); //} //if (!appt.TermsAccepted) //{ // ModelState.AddModelError("TermsAccepted", "You must accept the terms"); //} //if (ModelState.IsValidField("ClientName") && ModelState.IsValidField("Date")) //{ // if(appt.ClientName == "Garfield" && appt.Date.DayOfWeek==DayOfWeek.Monday) // { // ModelState.AddModelError("", "Garfield cannot book appointments on Mondays"); // } //} if (ModelState.IsValid) { return View("Completed", appt); } return View(); }
public ViewResult MakeBooking(Appointment appointment) { if (ModelState.IsValid) return View("Completed", appointment); return View(); }
public ViewResult MakeBooking(Appointment appt) { if (ModelState.IsValid) { // statements to store new Appointment in a // repository would go here in a real project return View("Completed", appt); } else { return View(); } }
public ViewResult MakeBooking(Appointment appt) { // if (string.IsNullOrEmpty(appt.ClientName)) { // ModelState.AddModelError("ClientName", "Please enter your name1"); // } //if (ModelState.IsValidField("Date") && DateTime.Now > appt.Date) { // ModelState.AddModelError("Date", "Please entewr a date in the future"); // } //if (!appt.TermsAccepted) { // ModelState.AddModelError("TermsAccepted", "You must accept the terms"); // } // if (ModelState.IsValidField("ClientName") && ModelState.IsValidField("Date") // && appt.ClientName == "Joe" && appt.Date.Year == 2016) { // ModelState.AddModelError("", "Joe cannot cook appointments in 2016"); // } if (ModelState.IsValid) { // statements to store new Appointment in a // repository would go here in a real project return View("Completed", appt); } else { return View(); } }
public ActionResult MakeBooking(Appointment appt) { ////Explicit Validation(Check every field explicitly) //if (string.IsNullOrEmpty(appt.ClientName)) //{ // ModelState.AddModelError("ClientName", "Please enter your name"); //} //if (ModelState.IsValidField("Date") && DateTime.Now > appt.Date) //{ // ModelState.AddModelError("Date", "Please enter a date in the future"); //} //if (!appt.TermsAccepted) //{ // ModelState.AddModelError("TermsAccepted", "You must accept the terms"); //} //if (ModelState.IsValidField("ClientName") && ModelState.IsValidField("Date")) //{ // if (appt.ClientName == "Garfield" && appt.Date.DayOfWeek == DayOfWeek.Monday) // { // ModelState.AddModelError("", "Garfield can not book appointments on Mondays"); // //first string is empty because there is no specific error. // //It is a model level error, not a property level error. // } //} if (ModelState.IsValid) //If there are no errors, return completed view { return View("Completed", appt); } //Otherwise return view return View(); }