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
Clare O'HareAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Take a look at this article that explains the basics of AJAX requests with MVC5

http://eliot-jones.com/2014/09/mvc-ajax

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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.