From 530b4943282e49dc1e5ce0e49593eb0ce97baaee Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Mon, 17 Feb 2020 15:42:19 +0800 Subject: [PATCH] update Former-commit-id: 700319900bdac5cb88439e5290f33e8778b0ce42 --- projects/Infrastructure/Data/EfDbContext.cs | 15 ++------------- projects/IoT.Shared/Services/DataService.cs | 11 ++++++++++- projects/WebApp/wwwroot/pages/home.html | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/projects/Infrastructure/Data/EfDbContext.cs b/projects/Infrastructure/Data/EfDbContext.cs index 74427281..001edcc8 100644 --- a/projects/Infrastructure/Data/EfDbContext.cs +++ b/projects/Infrastructure/Data/EfDbContext.cs @@ -14,15 +14,11 @@ namespace Infrastructure.Data { public class EfDbContext : DbContext { - public static readonly ILoggerFactory DebugLogFactory = LoggerFactory.Create(builder => + public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); }); - public static readonly ILoggerFactory ProductLogFactory = LoggerFactory.Create(builder => - { - }); - private readonly IHostEnvironment _env; private readonly IConfiguration _cfg; @@ -34,14 +30,7 @@ namespace Infrastructure.Data protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - if (this._cfg.GetValue("debug", false)) - { - optionsBuilder?.UseLoggerFactory(DebugLogFactory); - } - else - { - optionsBuilder?.UseLoggerFactory(ProductLogFactory); - } + optionsBuilder?.UseLoggerFactory(MyLoggerFactory); optionsBuilder?.EnableSensitiveDataLogging(); base.OnConfiguring(optionsBuilder); } diff --git a/projects/IoT.Shared/Services/DataService.cs b/projects/IoT.Shared/Services/DataService.cs index ffeed65f..9d90e131 100644 --- a/projects/IoT.Shared/Services/DataService.cs +++ b/projects/IoT.Shared/Services/DataService.cs @@ -1,8 +1,10 @@ -using Infrastructure.Application; +using Application.Domain.Entities; +using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Domain; using Infrastructure.Events; using Infrastructure.Extensions; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; @@ -84,6 +86,13 @@ namespace IoT.Shared.Services entity.From(model); if (repo.SaveChanges() > 0) { + if (entity is Data) + { + var data = entity as Data; + data.Device = scope.ServiceProvider.GetService>().ReadOnlyTable().Include(o => o.Node) + .Where(o => o.Id == data.DeviceId) + .Select(o => new Device { DisplayName = o.DisplayName, Node = new Node { Name = o.Node.Name } }).FirstOrDefault(); + } var eventPublisher = scope.ServiceProvider.GetService(); if (isNew) { diff --git a/projects/WebApp/wwwroot/pages/home.html b/projects/WebApp/wwwroot/pages/home.html index edb80f1b..2ccab357 100644 --- a/projects/WebApp/wwwroot/pages/home.html +++ b/projects/WebApp/wwwroot/pages/home.html @@ -4,7 +4,7 @@
- {{message.name}}:{{message.value}} {{message.unit}} {{message.description}} + {{message.device.node.name}}{{message.device.displayName}}{{message.name}}:{{message.value}} {{message.unit}} {{message.description}}