LevelsRiversController.cs
4.06 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json.Linq;
using ControlPanel.Models;
using System.Runtime.Serialization;
using ControlPanel.LogicLayers;
using System.IO;
namespace ControlPanel.Controllers
{
public class LevelsRiversController : ApiController
{
// POST api/default1
public string Post(JObject data)
{
string error = "Ok";
System.IO.StreamWriter StreamWriter = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/Output/data.txt"),true);
try
{
var lst = data["data"];
foreach (var p in lst)
{
dynamic json = JValue.Parse(p.ToString());
int id_agk = json.id_agk;
if (id_agk > 1000)
id_agk = id_agk - 1000;
bool repair = false; // в норме
bool opendoor = false; // дверь закрыта
// если поля существует , то присвоим значение из JSON объека
try
{
int r = json.repair;
int f = json.opendoor;
if (r == 1)
repair = true;
if (f == 1)
opendoor = true;
}
catch (Exception)
{
}
MsgLevelRiver mslevelriver = new MsgLevelRiver
{
id_agk=id_agk,
datetimedevice = json.datetimedevice,
datetimeveracity = json.datetimeveracity,
datetimeserver = json.datetimeserver,
latitude = json.latitude,
longitude = json.longitude,
coordveracity = json.coordveracity,
installplace = json.installplace,
levelbsv = json.levelbsv,
levelpointsuspen = json.levelpointsuspen,
levelzeropost = json.levelzeropost,
causeevent = json.causeevent,
repair = repair,
opendoor = opendoor
};
try
{
string river = json.installplace;
Agk agk = new Agk();
agk.number = id_agk;
agk.river = river;
agk.latitude = mslevelriver.latitude;
agk.longitude = mslevelriver.longitude;
LogicAgk.instance.Add(agk);
//добавляем/ обновляем таблицу оповещаний //
//Notification objnotification = new Notification { number = agk.number, river = river, notification = true };
//LogicNotification.instance.Add(objnotification);
}
catch (Exception ex)
{
StreamWriter.WriteLine(ex.Message);
}
LogicLevelsRivers.instance.InsLevelsRivers(mslevelriver);
}
}
catch (Exception ex)
{
StreamWriter.WriteLine(ex.Message);
}
StreamWriter.Flush();
StreamWriter.Close();
return error;
}
// PUT api/default1/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/default1/5
public void Delete(int id)
{
}
}
}