Booking system - Availabilty check with Ajax to database

Clare O'Hare
Clare O'Hare used Ask the Experts™
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
        public Guid BookingId { get; set; }

        public Guid PatientId { get; set; }
        public virtual Patient Patient { get; set; }
        public IEnumerable<SelectListItem> PatientList { get; set; }

        public Guid PracticeId { get; set; }
        public virtual Practice Practice { get; set; }
        public IEnumerable<SelectListItem> PracticeList { get; set; }

        public Guid OpticianId { get; set; }
        public virtual Optician Optician { get; set; }
        public IEnumerable<SelectListItem> OpticiansList { get; set; }

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

        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
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Take a look at this article that explains the basics of AJAX requests with MVC5

You can also Google .Net MVC5 ajax to find more resources on AJAX and MVC5

After that - post back any specific questions that you may have along with any supporting code you have so far.

Ajax is fairly simple once you understand the basics - for the most part I use AJAX directly - with .Net it is wrapped up for you in controls and other mechanisms - hence my pointer to the article above.

An AJAX request is just a browser request to your server - so you need to create a service / page on your site that listens for that request. This process takes as input the parameters you need to perform your validation. You then write your C# code to check your database using the parameters you received from the AJAX call - which would have been passed in by POST or GET requests (just like a normal URL or Form POST). Once you have your answer you create a response in the format the AJAX routine is expecting - this can be a JSON response or HTML or plain TEXT - there are many options. This is then simply output as you would a normal web page and is automatically transferred back to the AJAX routine which then processes the response and performs whatever action you need it to (using JavaScript / jQuery) in the browser.

Those are the basics - start from there and post back with questions you may have.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial