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

Add AddDeviceIdentity

Add ApiResult
上级 1e6d8f69
......@@ -6,10 +6,12 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using IoTSharp.Hub.Data;
using Microsoft.AspNetCore.Authorization;
namespace IoTSharp.Hub.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class CustomersController : ControllerBase
{
......@@ -22,12 +24,22 @@ namespace IoTSharp.Hub.Controllers
// GET: api/Tenants
[HttpGet("Tenant/{tenantId}")]
[Authorize(Roles = nameof(UserRole.NormalUser))]
public async Task<ActionResult<IEnumerable<Customer>>> GetCustomers(Guid tenantId)
{
return (await _context.Tenant.FindAsync(tenantId)).Customers?.ToList();
var f = from c in _context.Customer where c.Tenant.Id == tenantId select c;
if (!f.Any())
{
return NotFound();
}
else
{
return await f.ToArrayAsync();
}
}
// GET: api/Customers/5
[Authorize(Roles = nameof(UserRole.NormalUser))]
[HttpGet("{id}")]
public async Task<ActionResult<Customer>> GetCustomer(Guid id)
{
......@@ -42,6 +54,7 @@ namespace IoTSharp.Hub.Controllers
}
// PUT: api/Customers/5
[Authorize(Roles = nameof(UserRole.CustomerAdmin))]
[HttpPut("{id}")]
public async Task<IActionResult> PutCustomer(Guid id, Customer customer)
{
......@@ -49,12 +62,7 @@ namespace IoTSharp.Hub.Controllers
{
return BadRequest();
}
var tent=await _context.Tenant.FindAsync(customer.Id);
if (tent == null)
{
return NotFound();
}
customer.Tenant = tent;
customer.Tenant = _context.Tenant.Find(customer.Tenant.Id);
_context.Entry(customer).State = EntityState.Modified;
try
{
......@@ -76,16 +84,18 @@ namespace IoTSharp.Hub.Controllers
}
// POST: api/Customers
[Authorize(Roles = nameof(UserRole.CustomerAdmin))]
[HttpPost]
public async Task<ActionResult<Customer>> PostCustomer(Customer customer)
{
customer.Tenant= _context.Tenant.Find(customer.Tenant.Id);
customer.Tenant = _context.Tenant.Find(customer.Tenant.Id);
_context.Customer.Add(customer);
await _context.SaveChangesAsync();
return CreatedAtAction("GetCustomer",customer.Id);
return await GetCustomer(customer.Id);
}
// DELETE: api/Customers/5
[Authorize(Roles = nameof(UserRole.TenantAdmin))]
[HttpDelete("{id}")]
public async Task<ActionResult<Customer>> DeleteCustomer(Guid id)
{
......@@ -108,7 +118,7 @@ namespace IoTSharp.Hub.Controllers
public class TenantDto
{
public Guid Id { get; set; }
public Guid Id { get; set; }
}
}
}
}
\ No newline at end of file
......@@ -6,10 +6,13 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using IoTSharp.Hub.Data;
using Microsoft.AspNetCore.Authorization;
using IoTSharp.Hub.Dtos;
namespace IoTSharp.Hub.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class DevicesController : ControllerBase
{
......@@ -21,13 +24,24 @@ namespace IoTSharp.Hub.Controllers
}
// GET: api/Devices
[HttpGet("Customers/{customerId}")]
[Authorize(Roles = nameof(UserRole.NormalUser))]
[HttpGet]
public async Task<ActionResult<IEnumerable<Device>>> GetDevice()
public async Task<ActionResult<IEnumerable<Device>>> GetDevices(Guid customerId)
{
return await _context.Device.ToListAsync();
var f = from c in _context.Device where c.Customer.Id == customerId select c;
if (!f.Any())
{
return NotFound(new ApiResult<Guid>(ApiCode.NotFoundCustomer, $"Customer {customerId} not found ", customerId));
}
else
{
return await f.ToArrayAsync();
}
}
// GET: api/Devices/5
[Authorize(Roles = nameof(UserRole.NormalUser))]
[HttpGet("{id}")]
public async Task<ActionResult<Device>> GetDevice(Guid id)
{
......@@ -35,13 +49,14 @@ namespace IoTSharp.Hub.Controllers
if (device == null)
{
return NotFound();
return NotFound(new ApiResult<Guid>(ApiCode.NotFoundDevice, $"Device {id} not found ", id));
}
return device;
}
// PUT: api/Devices/5
[Authorize(Roles = nameof(UserRole.CustomerAdmin))]
[HttpPut("{id}")]
public async Task<IActionResult> PutDevice(Guid id, Device device)
{
......@@ -60,7 +75,7 @@ namespace IoTSharp.Hub.Controllers
{
if (!DeviceExists(id))
{
return NotFound();
return NotFound(new ApiResult<Guid>(ApiCode.NotFoundDevice, $"Device {id} not found ", id));
}
else
{
......@@ -72,23 +87,30 @@ namespace IoTSharp.Hub.Controllers
}
// POST: api/Devices
[Authorize(Roles = nameof(UserRole.CustomerAdmin))]
[HttpPost]
public async Task<ActionResult<Device>> PostDevice(Device device)
{
device.Tenant = _context.Tenant.Find(device.Tenant.Id);
device.Customer = _context.Customer.Find(device.Customer.Id);
if (device.Tenant == null || device.Customer == null)
{
return NotFound(new ApiResult<Device>(ApiCode.NotFoundTenantOrCustomer, $"Not found Tenant or Customer ", device));
}
_context.Device.Add(device);
await _context.SaveChangesAsync();
return CreatedAtAction("GetDevice", new { id = device.Id }, device);
return await GetDevice(device.Id);
}
// DELETE: api/Devices/5
[Authorize(Roles = nameof(UserRole.CustomerAdmin))]
[HttpDelete("{id}")]
public async Task<ActionResult<Device>> DeleteDevice(Guid id)
{
var device = await _context.Device.FindAsync(id);
if (device == null)
{
return NotFound();
return NotFound(new ApiResult<Guid>(ApiCode.NotFoundDevice, $"Device {id} not found ", id));
}
_context.Device.Remove(device);
......@@ -102,4 +124,4 @@ namespace IoTSharp.Hub.Controllers
return _context.Device.Any(e => e.Id == id);
}
}
}
}
\ No newline at end of file
......@@ -22,7 +22,6 @@ namespace IoTSharp.Hub.Controllers
private ApplicationDbContext _context;
private ILogger _logger;
private readonly UserManager<IdentityUser> _userManager;
private readonly IConfiguration _configuration;
private readonly SignInManager<IdentityUser> _signInManager;
public TenantsController(
......
......@@ -24,7 +24,6 @@ namespace IoTSharp.Hub.Data
{
Database.Migrate();
}
}
public DatabaseType DatabaseType { get; private set; }
......@@ -32,7 +31,7 @@ namespace IoTSharp.Hub.Data
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<DataStorage>()
.HasDiscriminator<DataCatalog>(nameof(Data.DataStorage.Catalog))
.HasValue<DataStorage>(DataCatalog.None)
......@@ -45,9 +44,6 @@ namespace IoTSharp.Hub.Data
modelBuilder.Entity<AttributeLatest>().HasDiscriminator<DataCatalog>(nameof(Data.DataStorage.Catalog));
modelBuilder.Entity<TelemetryData>().HasDiscriminator<DataCatalog>(nameof(Data.DataStorage.Catalog));
modelBuilder.Entity<TelemetryLatest>().HasDiscriminator<DataCatalog>(nameof(Data.DataStorage.Catalog));
switch (DatabaseType)
{
......@@ -67,7 +63,6 @@ namespace IoTSharp.Hub.Data
}
}
private void ForNpgsql(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TelemetryData>()
......@@ -131,5 +126,6 @@ namespace IoTSharp.Hub.Data
public DbSet<DataStorage> DataStorage { get; set; }
public DbSet<AttributeData> AttributeData { get; set; }
public DbSet<TelemetryLatest> TelemetryLatest { get; set; }
public DbSet<DeviceIdentity> DeviceIdentities { get; set; }
}
}
\ No newline at end of file
......@@ -7,20 +7,19 @@ namespace IoTSharp.Hub.Data
{
public class Device
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { get; set; }
public string Type { get; set; }
public Tenant Tenant { get; set; }
public Tenant Tenant { get; set; }
public Customer Customer { get; set; }
public Customer Customer { get; set; }
public virtual List<AttributeData> AttributeData { get; set; }
public virtual List<AttributeLatest> AttributeLatest { get; set; }
public virtual List<TelemetryData> TelemetryData { get; set; }
public virtual List<TelemetryData> TelemetryData { get; set; }
public virtual List<TelemetryLatest> TelemetryLatest { get; set; }
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace IoTSharp.Hub.Data
{
public class DeviceIdentity
{
[Key]
public Guid Id { get; set; }
[Required]
[EnumDataType(typeof(IdentityType))]
public IdentityType IdentityType { get; set; }
/// <summary>
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.AccessToken"/> ,this is a Token.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.DevicePassword"/> ,this is a device name.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.X509Certificate"/> ,this is X509 Certificate' Fingerprint.
/// </summary>
[Required]
public string IdentityId { get; set; }
/// <summary>
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.AccessToken"/> ,this is null.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.DevicePassword"/> ,this is a password.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.X509Certificate"/> ,this is X509 Certificate' PEM.
/// </summary>
public string IdentityValue { get; set; }
[Required]
public Device Device { get; set; }
}
}
\ No newline at end of file
......@@ -9,17 +9,21 @@ namespace IoTSharp.Hub.Data
{
public static class IoTSharpClaimTypes
{
public const string Customer = "http://schemas.iotsharp.net/ws/2019/01/identity/claims/customer";
public const string Tenant = "http://schemas.iotsharp.net/ws/2019/01/identity/claims/tenant";
}
public enum ApiCode:int
public enum ApiCode : int
{
Success= 10000,
LoginError=10001,
Success = 10000,
LoginError = 10001,
Exception = 10002,
AlreadyExists = 10003,
NotFoundTenantOrCustomer = 10004,
NotFoundDevice = 10005,
NotFoundCustomer = 10006,
}
public enum DataCatalog
{
None,
......@@ -27,8 +31,8 @@ namespace IoTSharp.Hub.Data
AttributeLatest,
TelemetryData,
TelemetryLatest,
}
public enum UserRole
{
Anonymous,
......@@ -36,7 +40,6 @@ namespace IoTSharp.Hub.Data
CustomerAdmin,
TenantAdmin,
SystemAdmin,
}
public enum DataType
......@@ -49,10 +52,18 @@ namespace IoTSharp.Hub.Data
XML,
Binary
}
public enum DatabaseType
{
mssql,
npgsql,
sqlite
}
}
public enum IdentityType
{
AccessToken,
DevicePassword,
X509Certificate
}
}
\ No newline at end of file
// <auto-generated />
using System;
using IoTSharp.Hub.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace IoTSharp.Hub.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20190118115805_AddDeviceIdentity")]
partial class AddDeviceIdentity
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("IoTSharp.Hub.Data.Customer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Address");
b.Property<string>("City");
b.Property<string>("Country");
b.Property<string>("Email");
b.Property<string>("Name");
b.Property<string>("Phone");
b.Property<string>("Province");
b.Property<string>("Street");
b.Property<Guid?>("TenantId");
b.Property<int>("ZipCode");
b.HasKey("Id");
b.HasIndex("TenantId");
b.ToTable("Customer");
});
modelBuilder.Entity("IoTSharp.Hub.Data.DataStorage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("Catalog");
b.Property<DateTime>("DateTime");
b.Property<string>("KeyName")
.IsRequired();
b.Property<int>("Type");
b.Property<byte[]>("Value_Binary");
b.Property<bool>("Value_Boolean");
b.Property<double>("Value_Double");
b.Property<string>("Value_Json")
.HasColumnType("jsonb");
b.Property<long>("Value_Long");
b.Property<string>("Value_String");
b.Property<string>("Value_XML")
.HasColumnType("xml");
b.HasKey("Id");
b.ToTable("DataStorage");
b.HasDiscriminator<int>("Catalog").HasValue(0);
});
modelBuilder.Entity("IoTSharp.Hub.Data.Device", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid?>("CustomerId");
b.Property<string>("Name");
b.Property<Guid?>("TenantId");
b.Property<string>("Type");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("TenantId");
b.ToTable("Device");
});
modelBuilder.Entity("IoTSharp.Hub.Data.DeviceIdentity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid>("DeviceId");
b.Property<string>("IdentityId")
.IsRequired();
b.Property<int>("IdentityType");
b.Property<string>("IdentityValue");
b.HasKey("Id");
b.HasIndex("DeviceId");
b.ToTable("DeviceIdentities");
});
modelBuilder.Entity("IoTSharp.Hub.Data.Relationship", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid?>("CustomerId");
b.Property<string>("IdentityUserId");
b.Property<Guid?>("TenantId");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("IdentityUserId");
b.HasIndex("TenantId");
b.ToTable("Relationship");
});
modelBuilder.Entity("IoTSharp.Hub.Data.Tenant", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Address");
b.Property<string>("City");
b.Property<string>("Country");
b.Property<string>("EMail");
b.Property<string>("Name");
b.Property<string>("Phone");
b.Property<string>("Province");
b.Property<string>("Street");
b.Property<int>("ZipCode");
b.HasKey("Id");
b.ToTable("Tenant");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Name")
.HasMaxLength(256);
b.Property<string>("NormalizedName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ClaimType");
b.Property<string>("ClaimValue");
b.Property<string>("RoleId")
.IsRequired();
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AccessFailedCount");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Email")
.HasMaxLength(256);
b.Property<bool>("EmailConfirmed");
b.Property<bool>("LockoutEnabled");
b.Property<DateTimeOffset?>("LockoutEnd");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256);
b.Property<string>("NormalizedUserName")
.HasMaxLength(256);
b.Property<string>("PasswordHash");
b.Property<string>("PhoneNumber");
b.Property<bool>("PhoneNumberConfirmed");
b.Property<string>("SecurityStamp");
b.Property<bool>("TwoFactorEnabled");
b.Property<string>("UserName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasName("UserNameIndex");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ClaimType");
b.Property<string>("ClaimValue");
b.Property<string>("UserId")
.IsRequired();
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider");
b.Property<string>("ProviderKey");
b.Property<string>("ProviderDisplayName");
b.Property<string>("UserId")
.IsRequired();
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId");
b.Property<string>("RoleId");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId");
b.Property<string>("LoginProvider");
b.Property<string>("Name");
b.Property<string>("Value");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("IoTSharp.Hub.Data.AttributeData", b =>
{
b.HasBaseType("IoTSharp.Hub.Data.DataStorage");
b.Property<Guid>("DeviceId");
b.HasIndex("DeviceId");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Hub.Data.AttributeLatest", b =>
{
b.HasBaseType("IoTSharp.Hub.Data.DataStorage");
b.Property<Guid>("DeviceId")
.HasColumnName("AttributeLatest_DeviceId");
b.HasIndex("DeviceId");
b.HasDiscriminator().HasValue(2);
});
modelBuilder.Entity("IoTSharp.Hub.Data.TelemetryData", b =>
{
b.HasBaseType("IoTSharp.Hub.Data.DataStorage");
b.Property<Guid>("DeviceId")
.HasColumnName("TelemetryData_DeviceId");
b.HasIndex("DeviceId");
b.HasDiscriminator().HasValue(3);
});
modelBuilder.Entity("IoTSharp.Hub.Data.TelemetryLatest", b =>
{
b.HasBaseType("IoTSharp.Hub.Data.DataStorage");
b.Property<Guid>("DeviceId")
.HasColumnName("TelemetryLatest_DeviceId");
b.HasIndex("DeviceId");
b.HasDiscriminator().HasValue(4);
});
modelBuilder.Entity("IoTSharp.Hub.Data.Customer", b =>
{
b.HasOne("IoTSharp.Hub.Data.Tenant", "Tenant")
.WithMany("Customers")
.HasForeignKey("TenantId");
});
modelBuilder.Entity("IoTSharp.Hub.Data.Device", b =>
{
b.HasOne("IoTSharp.Hub.Data.Customer", "Customer")
.WithMany("Devices")
.HasForeignKey("CustomerId");
b.HasOne("IoTSharp.Hub.Data.Tenant", "Tenant")
.WithMany("Devices")
.HasForeignKey("TenantId");
});
modelBuilder.Entity("IoTSharp.Hub.Data.DeviceIdentity", b =>
{
b.HasOne("IoTSharp.Hub.Data.Device", "Device")
.WithMany()
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("IoTSharp.Hub.Data.Relationship", b =>
{
b.HasOne("IoTSharp.Hub.Data.Customer", "Customer")
.WithMany()
.HasForeignKey("CustomerId");
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "IdentityUser")
.WithMany()
.HasForeignKey("IdentityUserId");
b.HasOne("IoTSharp.Hub.Data.Tenant", "Tenant")
.WithMany()
.HasForeignKey("TenantId");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("IoTSharp.Hub.Data.AttributeData", b =>
{
b.HasOne("IoTSharp.Hub.Data.Device", "Device")
.WithMany("AttributeData")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("IoTSharp.Hub.Data.AttributeLatest", b =>
{
b.HasOne("IoTSharp.Hub.Data.Device", "Device")
.WithMany("AttributeLatest")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("IoTSharp.Hub.Data.TelemetryData", b =>
{
b.HasOne("IoTSharp.Hub.Data.Device", "Device")
.WithMany("TelemetryData")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("IoTSharp.Hub.Data.TelemetryLatest", b =>
{
b.HasOne("IoTSharp.Hub.Data.Device", "Device")
.WithMany("TelemetryLatest")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}
}
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace IoTSharp.Hub.Migrations
{
public partial class AddDeviceIdentity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "DeviceIdentities",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
IdentityType = table.Column<int>(nullable: false),
IdentityId = table.Column<string>(nullable: false),
IdentityValue = table.Column<string>(nullable: true),
DeviceId = table.Column<Guid>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceIdentities", x => x.Id);
table.ForeignKey(
name: "FK_DeviceIdentities_Device_DeviceId",
column: x => x.DeviceId,
principalTable: "Device",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DeviceIdentities_DeviceId",
table: "DeviceIdentities",
column: "DeviceId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DeviceIdentities");
}
}
}
......@@ -110,6 +110,27 @@ namespace IoTSharp.Hub.Migrations
b.ToTable("Device");
});
modelBuilder.Entity("IoTSharp.Hub.Data.DeviceIdentity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid>("DeviceId");
b.Property<string>("IdentityId")
.IsRequired();
b.Property<int>("IdentityType");
b.Property<string>("IdentityValue");
b.HasKey("Id");
b.HasIndex("DeviceId");
b.ToTable("DeviceIdentities");
});
modelBuilder.Entity("IoTSharp.Hub.Data.Relationship", b =>
{
b.Property<Guid>("Id")
......@@ -382,6 +403,14 @@ namespace IoTSharp.Hub.Migrations
.HasForeignKey("TenantId");
});
modelBuilder.Entity("IoTSharp.Hub.Data.DeviceIdentity", b =>
{
b.HasOne("IoTSharp.Hub.Data.Device", "Device")
.WithMany()
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("IoTSharp.Hub.Data.Relationship", b =>
{
b.HasOne("IoTSharp.Hub.Data.Customer", "Customer")
......
using IoTSharp.Hub.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace IoTSharp.Hub.Dtos
{
public class ApiResult
{
public ApiResult()
{
}
public ApiResult(ApiCode _code, string _msg)
{
Code = (int)_code;
Msg = _msg;
}
public int Code { get; set; } = (int)ApiCode.Success;
public string Msg { get; set; } = "OK";
}
public class ApiResult<T> : ApiResult
{
public ApiResult(ApiCode _code, string _msg, T data) : base(_code, _msg)
{
Data = data;
}
public T Data { set; get; }
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册