コード例 #1
0
        // GET: api/EmergencyContact
        public ActionResult Get()
        {
            List <EmergencyContact> emergencyContacts = new EmergencyContactDAO().GetAllEmergencyContacts();

            if (emergencyContacts == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
            }
            JsonResult result = new JsonResult()
            {
                Data = emergencyContacts
            };

            return(result);
        }
コード例 #2
0
        // GET: api/EmergencyContact/5
        public ActionResult Get(string id)
        {
            EmergencyContact emergencyContact = new EmergencyContactDAO().GetEmergencyContactById(id);

            if (emergencyContact == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
            }

            JsonResult result = new JsonResult()
            {
                Data = emergencyContact
            };

            return(result);
        }
コード例 #3
0
        // POST: api/EmergencyContact
        public HttpResponseMessage Post([FromBody] string value)
        {
            System.Diagnostics.Debug.WriteLine(value);

            EmergencyContact emergencyContact = JsonConvert.DeserializeObject <EmergencyContact>(value);
            bool             result           = new EmergencyContactDAO().AddEmergencyContact(emergencyContact);

            if (result)
            {
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, emergencyContact);
                response.Headers.Location = new Uri(Request.RequestUri, string.Format("AdminAlert/{0}", emergencyContact.EmergencyNumber));
                return(response);
            }
            else
            {
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Conflict, emergencyContact);
                return(response);
            }
        }