示例#1
0
        public IHttpActionResult PostDoctor(DoctorModel doctor)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var dbDoctor = new Doctor();

            dbDoctor.Update(doctor);
            db.Doctors.Add(dbDoctor);
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {

                throw new Exception("Unable to add the doctor to the database");
            }

            doctor.DoctorID = dbDoctor.DoctorID;

            return CreatedAtRoute("DefaultApi", new { id = doctor.DoctorID }, doctor);
        }