提交 60702480 编写于 作者: 麦壳饼's avatar 麦壳饼

创建设备的时候使用DevicePostDto来进行单独创建, 而不是Device类,另外, 增加

上级 49cdf663
......@@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>
......
......@@ -185,21 +185,21 @@ namespace IoTSharp.Controllers
// POST: api/Devices
[Authorize(Roles = nameof(UserRole.CustomerAdmin))]
[HttpPost]
public async Task<ActionResult<Device>> PostDevice(Device device)
public async Task<ActionResult<Device>> PostDevice(DevicePostDto device)
{
var cid = User.Claims.First(c => c.Type == IoTSharpClaimTypes.Customer);
var tid = User.Claims.First(c => c.Type == IoTSharpClaimTypes.Tenant);
device.Tenant = _context.Tenant.Find(new Guid(tid.Value));
device.Customer = _context.Customer.Find(new Guid(cid.Value));
if (device.Tenant == null || device.Customer == null)
var devvalue = new Device() { Name = device.Name, DeviceType = device.DeviceType };
devvalue.Tenant = _context.Tenant.Find(new Guid(tid.Value));
devvalue.Customer = _context.Customer.Find(new Guid(cid.Value));
if (devvalue.Tenant == null || devvalue.Customer == null)
{
return NotFound(new ApiResult<Device>(ApiCode.NotFoundTenantOrCustomer, $"Not found Tenant or Customer ", device));
return NotFound(new ApiResult<DevicePostDto>(ApiCode.NotFoundTenantOrCustomer, $"Not found Tenant or Customer ", device));
}
_context.Device.Add(device);
_context.AfterCreateDevice(device);
_context.Device.Add(devvalue);
_context.AfterCreateDevice(devvalue);
await _context.SaveChangesAsync();
return await GetDevice(device.Id);
return await GetDevice(devvalue.Id);
}
// DELETE: api/Devices/5
......
using IoTSharp.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace IoTSharp.Dtos
{
public class DevicePostDto
{
public string Name { get; set; }
public DeviceType DeviceType { get; set; }
}
}
......@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RuntimeIdentifiers>win7-x64;rhel.7-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win7-x64;rhel.7-x64;ubuntu.18.04-x64</RuntimeIdentifiers>
<PreserveCompilationContext>true</PreserveCompilationContext>
<CreateUser>true</CreateUser>
<InstallService>true</InstallService>
......@@ -79,7 +79,7 @@
<PackageReference Include="MQTTnet.Extensions.Rpc" Version="3.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.4" />
<PackageReference Include="NSwag.AspNetCore" Version="12.3.1" />
<PackageReference Include="QuartzHostedService" Version="0.0.4" />
<PackageReference Include="QuartzHostedService" Version="0.0.5" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
</ItemGroup>
<ProjectExtensions>
......
......@@ -25,3 +25,15 @@ IoTSharp is an open-source IoT platform for data collection, processing, visuali
![IotSharp Logo](docs/images/iot_sharp_logo.png)
## How to install ?
- mkdir /var/lib/iotsharp/
- cp ./* /var/lib/iotsharp/
- chmod 777 /var/lib/iotsharp/IoTSharp
- cp iotsharp.service /etc/systemd/system/iotsharp.service
- sudo systemctl enable /etc/systemd/system/iotsharp.service
- sudo systemctl start iotsharp.service
- sudo journalctl -fu iotsharp.service
- http://127.0.0.1:80/
-
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册