OrdersController.cs
1.8 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
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/orders")]
public class OrdersController : ApiController
{
[HttpGet]
public IEnumerable<Order> Get()
{
return OrderManager.Load();
}
[Route("{name}")]
[HttpGet]
public Order Get(string name)
{
return OrderManager.GetOrder(name);
}
[HttpPost]
public Result Post([FromBody] Order order)
{
Result result = new Result();
bool rtn = OrderManager.CreateOrder(order, out string msg);
if (!rtn)
{
result.code = -1;
result.msg = $"Create order fail. {msg}";
}
result.data = JsonHelper.DeserializeJsonToObject<Dictionary<string, object>>(JsonHelper.SerializeObject(order));
return result;
}
[Route("{id}")]
[HttpDelete]
public Result Delete(string id, bool force = false)
{
Result result = new Result();
bool rtn = OrderManager.DeleteOrderById(id, out string msg, force);
if (!rtn)
{
result.code = -1;
result.msg = msg;
}
return result;
}
[Route("{typeId}")]
[HttpDelete]
public Result Delete(int typeId, bool force = false)
{
Result result = new Result();
bool rtn = OrderManager.DeleteOrderByType(typeId, out string msg, force);
if (!rtn)
{
result.code = -1;
result.msg = msg;
}
return result;
}
}
}