Ejemplo n.º 1
0
        public IHttpActionResult UpdateDentist(int id, Dentist dentist)
        {
            using (var db = new WebApiDemoDb1Entities())
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var dbDentist = db.Dentists.SingleOrDefault(x => x.Id == id);
                if (dbDentist == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }

                dbDentist.FirstName = dentist.FirstName;
                dbDentist.LastName  = dentist.LastName;
                dbDentist.Email     = dentist.Email;
                dbDentist.Phone     = dentist.Phone;

                db.SaveChanges();

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    throw;
                }
            }
            return(Ok("Dentist Record Updated Successfully!"));
        }
Ejemplo n.º 2
0
        public IHttpActionResult CreateDentist(Dentist dentist)
        {
            using (var db = new WebApiDemoDb1Entities())
            {
                if (!ModelState.IsValid)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }

                if (db.Dentists.Any(d => d.Phone == dentist.Phone || d.Email == dentist.Email))
                {
                    return(BadRequest("Record already exists!"));
                }

                var dbDentist = dentist.ToDatabase();
                db.Dentists.Add(dbDentist);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    throw;
                }
            }
            return(Ok("Dentist Reord Created Successfully!"));
        }