public IHttpActionResult CreatePatients(Patient patient)
        {
            using (var db = new WebApiDemoDb1Entities())
            {
                if (db.Dentists.Any(p => p.Email == patient.Email || p.Phone == patient.Phone))
                {
                    return(BadRequest("Patient record already exists"));
                }

                if (!ModelState.IsValid)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }

                var dbPatient = patient.ToDatabase();
                db.Patients.Add(dbPatient);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    throw;
                }
            }
            return(Ok("Successfully Created Patient Record!"));
        }
        public IHttpActionResult UpdatePatient(int id, Patient patient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbPatient = db.Patients.SingleOrDefault(p => p.Id == id);

            if (dbPatient == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            dbPatient.FirstName = patient.FirstName;
            dbPatient.LastName  = patient.LastName;
            dbPatient.Email     = patient.Email;
            dbPatient.Phone     = patient.Phone;
            dbPatient.Address   = patient.Address;
            dbPatient.DentistId = patient.DentistId;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(Ok("Patient Record Successfully Updated!"));
        }