Beispiel #1
0
        public IActionResult Put(string id, [FromBody] string value)
        {
            if (id == null)
            {
                return(StatusCode(400, "Provide ID for data"));
            }
            var updateddata = _context.UpdatedData.SingleOrDefault(u => u.DataID.Equals(id));

            if (updateddata == null)
            {
                return(StatusCode(400, "Data ID not found in database"));
            }
            if (!updateddata.Active)
            {
                return(StatusCode(200, UpdatedData.GetPointers(updateddata)));
            }

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(@"http://localhost:5000/api/updates");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpContent content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(updateddata));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage rm = client.PostAsync("", content).Result;

            return(StatusCode(400, rm.StatusCode.ToString() + rm.Content.ToString()));

            //
            //return StatusCode(400, "Request type not supported");
        }
Beispiel #2
0
        public IActionResult Get(string id)
        {
            if (id == null)
            {
                return(StatusCode(400, "Provide ID for data"));
            }
            var updateddata = _context.UpdatedData.SingleOrDefault(u => u.DataID.Equals(id));

            if (updateddata == null)
            {
                return(StatusCode(400, "Data ID not found in database"));
            }
            if (!updateddata.Active)
            {
                return(StatusCode(200, UpdatedData.GetPointers(updateddata)));
            }

            return(StatusCode(200, updateddata));
        }