diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index 976b8158..4f11ad24 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -382,7 +382,7 @@ namespace Infrastructure.Web var context = services.GetService(); if (context.Database.EnsureCreated()) { - if(!Env.IsDevelopment()) + if (!Env.IsDevelopment()) { var sql = context.GetService().GenerateCreateScript(); var file = "db.sql"; diff --git a/projects/IoTCenter/Api/SiteController.cs b/projects/IoTCenter/Api/SiteController.cs new file mode 100644 index 00000000..6df66172 --- /dev/null +++ b/projects/IoTCenter/Api/SiteController.cs @@ -0,0 +1,66 @@ +using Application.Domain.Entities; +using Infrastructure.Application.Services.Settings; +using Infrastructure.Data; +using Infrastructure.Extensions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace IoTCenter.Api.Controllers +{ + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]/[action]")] + [ApiController] + public class SiteController : ControllerBase + { + private readonly ILogger _logger; + private readonly ISettingService _settingService; + private readonly IRepository _userRepo; + + public SiteController( + ILogger logger, + ISettingService settingService, + IRepository userRepo) + { + this._logger = logger; + this._settingService = settingService; + this._userRepo = userRepo; + } + + public IActionResult GetSite() + { + try + { + var username = User.Identity.IsAuthenticated ? this.HttpContext.User.Identity.Name : null; + var permissions = new List(); + if (User.Identity.IsAuthenticated) + { + permissions = this._userRepo.ReadOnlyTable() + .Where(o => o.UserName == username) + .SelectMany(o => o.UserRoles) + .Select(o => o.Role) + .SelectMany(o => o.RolePermissions) + .Select(o => o.Permission) + .Select(o => o.Number) + .ToList(); + } + return Ok(new + { + logo = this._settingService.GetSetting("logo").Value, + name = this._settingService.GetSetting("name").Value, + copyright = this._settingService.GetSetting("copyright").Value, + version = Helper.Instance.GetVersion(), + username, + permissions + }); + } + catch (Exception ex) + { + this._logger.LogError(ex, ex.Message); + return Problem(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Domain/Organ.cs b/projects/IoTCenter/Application/Domain/Organ.cs index 8cad0096..55ce5f37 100644 --- a/projects/IoTCenter/Application/Domain/Organ.cs +++ b/projects/IoTCenter/Application/Domain/Organ.cs @@ -1,9 +1,11 @@ using Infrastructure.Domain; +using Infrastructure.Web.Mvc; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace IoTCenter.Application.Domain { + [GeneratedController] [Display(Name = "机构")] public class Organ : BaseEntity { diff --git a/projects/IoTCenter/Views/Home/Index.cshtml b/projects/IoTCenter/Views/Home/Index.cshtml index e1d231e9..ce7ded27 100644 --- a/projects/IoTCenter/Views/Home/Index.cshtml +++ b/projects/IoTCenter/Views/Home/Index.cshtml @@ -49,7 +49,7 @@ \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/pages/admin/list.html b/projects/WebMVC/wwwroot/pages/admin/list.html new file mode 100644 index 00000000..c5c19891 --- /dev/null +++ b/projects/WebMVC/wwwroot/pages/admin/list.html @@ -0,0 +1,14 @@ + + \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/pages/device.html b/projects/WebMVC/wwwroot/pages/device.html index 01e3fb70..90464323 100644 --- a/projects/WebMVC/wwwroot/pages/device.html +++ b/projects/WebMVC/wwwroot/pages/device.html @@ -1,5 +1,5 @@