Avatar of Clare O'Hare
Clare O'Hare
 asked on

Booking system - Availabilty check with Ajax to database

I am very new to MVC and I am trying to create a booking system in MVC5. I have set up a my database by EF code first. My booking table is:
     
     public class Booking
    {
       [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid BookingId { get; set; }

        [ForeignKey("Patient")]
        public Guid PatientId { get; set; }
        public virtual Patient Patient { get; set; }
        public IEnumerable<SelectListItem> PatientList { get; set; }

        [ForeignKey("Practice")]
        public Guid PracticeId { get; set; }
        public virtual Practice Practice { get; set; }
        public IEnumerable<SelectListItem> PracticeList { get; set; }

        [ForeignKey("Optician")]
        public Guid OpticianId { get; set; }
        public virtual Optician Optician { get; set; }
        public IEnumerable<SelectListItem> OpticiansList { get; set; }

        [Display(Name = "Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime Date { get; set; }

        [ForeignKey("Time")]
        public Guid? TimeId { get; set; }
        public virtual Time Time { get; set; }
        public IEnumerable<SelectListItem> TimeList { get; set; }
        
        public bool isAvail { get; set; }
    }

Open in new window

I have used CRUD to make a Create page. Once a booking has been made the isAvail boolean is set to False.
What I am trying to do is create an AJAX query so that once the user selects the practice, optician and date the ajax query checks the database to see if the combination of practice, optician and date does not exist alongside isAvail - false in order to prevent double bookings. The ajax query would then return the available times ie - the time where there is no isAvail = false.

Any help would be greatly appreciated
Thanks
AJAX

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck