コード例 #1
0
        public HttpResponseMessage Create(Hl7.Fhir.Model.Observation fhirObservation)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Observation observation = ObservationMapper.MapResource(fhirObservation);

            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.CREATE);

            db.Observations.Add(observation);
            db.SaveChanges();

            message.Content          = new StringContent("Observation created!", Encoding.UTF8, "text/html");
            message.StatusCode       = HttpStatusCode.Created;
            message.Headers.Location = new Uri(Url.Link("SpecificObservation", new { id = observation.ObservationId }));

            return(message);
        }
コード例 #2
0
        public HttpResponseMessage Create(Hl7.Fhir.Model.Device fhirDevice)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Device device = DeviceMapper.MapResource(fhirDevice);

            device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.CREATE);

            db.Devices.Add(device);
            db.SaveChanges();

            message.Content          = new StringContent("Device created!", Encoding.UTF8, "text/html");
            message.StatusCode       = HttpStatusCode.Created;
            message.Headers.Location = new Uri(Url.Link("SpecificDevice", new { id = device.DeviceId }));

            return(message);
        }
コード例 #3
0
        public HttpResponseMessage Delete(int observationId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Observation observation = db.Observations.Find(observationId);

            if (observation == null)
            {
                message.StatusCode = HttpStatusCode.NotFound;
                message.Content    = new StringContent("Observation with id " + observationId + " not found!", Encoding.UTF8, "text/html");
                return(message);
            }
            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.DELETE);

            db.Observations.Remove(observation);
            db.SaveChanges();

            message.StatusCode = HttpStatusCode.NoContent;
            return(message);
        }
コード例 #4
0
        public HttpResponseMessage Delete(int deviceId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Device device = db.Devices.Find(deviceId);

            if (device == null)
            {
                message.StatusCode = HttpStatusCode.NotFound;
                message.Content    = new StringContent("Device with id " + deviceId + " not found!", Encoding.UTF8, "text/html");
                return(message);
            }
            device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.DELETE);

            db.Devices.Remove(device);
            db.SaveChanges();

            message.StatusCode = HttpStatusCode.NoContent;
            return(message);
        }
コード例 #5
0
        public HttpResponseMessage Update(Hl7.Fhir.Model.Observation fhirObservation, int observationId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            if (observationId != int.Parse(fhirObservation.Id))
            {
                message.StatusCode = HttpStatusCode.BadRequest;
                message.Content    = new StringContent("Mismatch of observation ID! Provided " + observationId + " in URL but found " + fhirObservation.Id + "in payload!", Encoding.UTF8, "text/html");
                return(message);
            }

            Observation observation = ObservationMapper.MapResource(fhirObservation);

            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.UPDATE);

            db.Entry(observation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ObservationExists(observationId))
                {
                    message.StatusCode = HttpStatusCode.NotFound;
                    message.Content    = new StringContent("observation with id " + observationId + " not found!", Encoding.UTF8, "text/html");
                    return(message);
                }
                else
                {
                    throw;
                }
            }

            message.StatusCode = HttpStatusCode.OK;
            return(message);
        }
コード例 #6
0
        public HttpResponseMessage Update(Hl7.Fhir.Model.Device fhirDevice, int deviceId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            if (deviceId != int.Parse(fhirDevice.Id))
            {
                message.StatusCode = HttpStatusCode.BadRequest;
                message.Content    = new StringContent("Mismatch of Device ID! Provided " + deviceId + " in URL but found " + fhirDevice.Id + "in payload!", Encoding.UTF8, "text/html");
                return(message);
            }

            Device device = DeviceMapper.MapResource(fhirDevice);

            device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.UPDATE);

            db.Entry(device).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeviceExists(deviceId))
                {
                    message.StatusCode = HttpStatusCode.NotFound;
                    message.Content    = new StringContent("Device with id " + deviceId + " not found!", Encoding.UTF8, "text/html");
                    return(message);
                }
                else
                {
                    throw;
                }
            }

            message.StatusCode = HttpStatusCode.OK;
            return(message);
        }