89 lines
2.6 KiB
C#
89 lines
2.6 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Runtime.Remoting.Contexts;
|
|
using System.Security.Principal;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Http.Results;
|
|
|
|
namespace Project.Controller
|
|
{
|
|
public class StateController : ApiController
|
|
{
|
|
//private static List<Item> _values = new List<Item> {
|
|
// new Item { Id = 1, Name = "USB2.0 Extension Cable" },
|
|
// new Item { Id = 2, Name = "USB3.0 Extension Cable" },
|
|
// new Item { Id =3, Name = "USB3.1 Extension Cable" }
|
|
//};
|
|
|
|
// GET api/values
|
|
public IHttpActionResult Get()
|
|
{
|
|
HttpResponseMessage responsem = new HttpResponseMessage(HttpStatusCode.OK);
|
|
//responsem.Headers.Add("Content-Type", "application/json");
|
|
//ResponseMessageResult response = new ResponseMessageResult(responsem);
|
|
//return response;
|
|
|
|
//return this.Content(HttpStatusCode.OK, _values, mediaType)
|
|
return Ok();
|
|
//string json = JsonConvert.SerializeObject(_values, Formatting.Indented);
|
|
//return Ok(json);
|
|
}
|
|
|
|
// GET api/values/5
|
|
public IHttpActionResult Get(int id)
|
|
{
|
|
//var value = DataManager.Items?.Find(v => v.Id == id) ?? null;
|
|
//if (value == null)
|
|
//{
|
|
// return NotFound();
|
|
//}
|
|
return Ok();
|
|
}
|
|
|
|
// POST api/values
|
|
public IHttpActionResult Post([FromBody] JObject value)
|
|
{
|
|
//value.Id = DataManager.Items?.Count ?? 0;
|
|
//DataManager.Items.Add(value);
|
|
//DataManager.Save();
|
|
return CreatedAtRoute("DefaultApi", new { id = value }, value);
|
|
}
|
|
|
|
// PUT api/values/5
|
|
public IHttpActionResult Put(int id, [FromBody] JObject value)
|
|
{
|
|
//var index = DataManager.Items.FindIndex(v => v.Id == id);
|
|
//if (index == -1)
|
|
//{
|
|
// return NotFound();
|
|
//}
|
|
|
|
//DataManager.Items[index] = value;
|
|
//DataManager.Save();
|
|
return Ok();
|
|
}
|
|
|
|
// DELETE api/values/5
|
|
public IHttpActionResult Delete(int id)
|
|
{
|
|
//var index = DataManager.Items.FindIndex(v => v.Id == id);
|
|
//if (index == -1)
|
|
//{
|
|
// return NotFound();
|
|
//}
|
|
|
|
//DataManager.Items.RemoveAt(index);
|
|
//DataManager.Save();
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|