NodesController.cs
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Common;
using DeviceLib.BLL;
using DeviceLib.Model.AGV;
using DeviceLib.WebApi.Schemas;
using System.Collections.Generic;
using System.Web.Http;
namespace DeviceLib.WebApi.Controllers
{
[RoutePrefix("api/nodes")]
public class NodesController : ApiController
{
[HttpGet]
public IEnumerable<ClientNode> Get()
{
return NodeManager.GetClientNodes();
}
[HttpGet]
[Route("{name}")]
public ClientNode Get(string name)
{
return NodeManager.GetClientNodeByName(name);
}
[HttpGet]
[Route("confirm")]
public Result ConfirmGet(string name, int id)
{
Result result = new Result();
result.data = new Dictionary<string, object>();
result.data.Add("name", name);
result.data.Add("id", id);
if (!NodeManager.NodeConfirm(id, name,out string msg))
{
result.code = -1;
result.msg = $"fail,{msg}";
}
return result;
}
[HttpPost]
public Result Post([FromBody] ClientNode node)
{
Result result = new Result();
bool rtn = NodeManager.AddNode(node);
if (!rtn)
{
result.code = -1;
result.msg = "fail";
}
result.data = JsonHelper.DeserializeJsonToObject<Dictionary<string, object>>(JsonHelper.SerializeObject(node));
return result;
}
[Route("{name}")]
[HttpPut]
public Result Put(string name, [FromBody] ClientNode node)
{
Result result = new Result();
bool rtn = NodeManager.UpdateClientNode(node);
if (!rtn)
{
result.code = -1;
result.msg = "fail";
}
result.data = JsonHelper.DeserializeJsonToObject<Dictionary<string, object>>(JsonHelper.SerializeObject(node));
return result;
}
[Route("{name}")]
[HttpDelete]
public Result Delete(string name)
{
Result result = new Result();
result.code = 0;
result.msg = "维护中";
return result;
}
}
}