Beispiel #1
0
        public IHttpActionResult PostHospital(Hospital hospital)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (CurrentUser.Hospital == null)
            {
                CurrentUser.Hospital = hospital;
            }
            else
            {
                return BadRequest("User already has a hospital");
            }
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = hospital.Id }, hospital);
        }
Beispiel #2
0
        public IHttpActionResult PutHospital(int id, Hospital hospital)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != hospital.Id || id != CurrentUser.Hospital.Id)
            {
                return BadRequest();
            }

            CurrentUser.Hospital.Address = hospital.Address;
            CurrentUser.Hospital.City = hospital.City;
            CurrentUser.Hospital.Name = hospital.Name;
            CurrentUser.Hospital.Phone = hospital.Phone;
            CurrentUser.Hospital.State = hospital.State;
            CurrentUser.Hospital.Zipcode = hospital.Zipcode;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HospitalExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }