public override IEnumerable <ModelValidationResult> Validate(object container)
        {
            Appointment4 appointment = container as Appointment4;

            if (appointment != null)
            {
                switch (Metadata.PropertyName)
                {
                case "ClientName":
                    if (string.IsNullOrWhiteSpace(appointment.ClientName))
                    {
                        return new[]
                               {
                                   new ModelValidationResult
                                   {
                                       MemberName = "",
                                       Message    = "Please enter your name [validator]",
                                   }
                               }
                    }
                    ;
                    break;

                case "Date":
                    if (appointment.Date == null || DateTime.Now.Date > appointment.Date)
                    {
                        return new[]
                               {
                                   new ModelValidationResult
                                   {
                                       MemberName = "",
                                       Message    = "Please enter a date in the future [validator]",
                                   }
                               }
                    }
                    ;
                    break;

                case "TermsAccepted":
                    if (!appointment.TermsAccepted)
                    {
                        return new[]
                               {
                                   new ModelValidationResult
                                   {
                                       MemberName = "",
                                       Message    = "You must accept the terms [validator]",
                                   }
                               }
                    }
                    ;
                    break;
                }
            }

            return(Enumerable.Empty <ModelValidationResult>());
        }
    }
        public ActionResult MakeBooking4(Appointment4 appointment)
        {
            if (ModelState.IsValid)
            {
                // Save appointment
                // ...

                return(View("Completed4", appointment));
            }
            else
            {
                return(View());
            }
        }
        public ActionResult AppointmentForm(Appointment4 appointmentModel)
        {
            ProjectDBEntities1        dbc = new ProjectDBEntities1();
            ProjectDBEntitiesSymptoms sym = new ProjectDBEntitiesSymptoms();
            DataClasses1DataContext   eve = new DataClasses1DataContext();

            using (ProjectDBEntities appModel = new ProjectDBEntities())
            {
                appModel.Appointment4.Add(appointmentModel);
                appModel.SaveChanges();
            }

            //Creating ViewBag to populate the Doctor dropdown list
            ViewBag.doctordrop = dbc.AspNetUserRoles.Where(x => x.RoleId == "e8f1347d-a369-4842-ac06-a4dee22150f1").Select(u => new SelectListItem
            {
                Value = u.UserId,
                Text  = u.UserId
            }).ToList();

            //Creating ViewBag to populate the Symptoms dropdown list
            ViewBag.symptoms = sym.Symptoms.Select(s => new SelectListItem
            {
                Value = s.Symptom1,
                Text  = s.Symptom1
            }).ToList();

            //Creating ViewBag to populate the appointment times dropdown list. It will only display appointments from todays date onwards.
            ViewBag.orderedTime = eve.Event1s.Where(x => x.eventstart >= DateTime.Today).OrderBy(x => x.eventstart).Select(t => new SelectListItem
            {
                Value = t.eventstart.ToString(),
                Text  = t.eventstart.ToString()
            }).ToList();

            //Creating a viewbag to populate ID field in the appointment form as a hidden field
            var currentUserID = User.Identity.GetUserId();

            ViewBag.currID = currentUserID;

            //Creating a viewbag to populate Email field in the appointment form as a hidden field
            var currentUserEmail = User.Identity.GetUserName();

            ViewBag.currEmail = currentUserEmail;

            ModelState.Clear();
            ViewBag.SuccessMessage = "Booking Successful.";
            return(View("AppointmentForm", new Appointment4()));
        }
Ejemplo n.º 4
0
        public override IEnumerable <ModelValidationResult> Validate(object container)
        {
            Appointment4 appointment = Metadata.Model as Appointment4;

            if (appointment != null &&
                appointment.ClientName == "Joe" &&
                appointment.Date.DayOfWeek == DayOfWeek.Monday)
            {
                return new[]
                       {
                           new ModelValidationResult
                           {
                               MemberName = "",
                               Message    = "Joe cannot book appointments on Mondays [validator]",
                           }
                       }
            }
            ;

            return(Enumerable.Empty <ModelValidationResult>());
        }
    }