|
|
|
@ -1,87 +1,87 @@
|
|
|
|
|
using Infrastructure.Application.Services.Settings;
|
|
|
|
|
using Infrastructure.Data;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Application.Domain.Entities;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
//using Infrastructure.Application.Services.Settings;
|
|
|
|
|
//using Infrastructure.Data;
|
|
|
|
|
//using Infrastructure.Extensions;
|
|
|
|
|
//using Application.Domain.Entities;
|
|
|
|
|
//using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
//using Microsoft.Extensions.Configuration;
|
|
|
|
|
//using Microsoft.Extensions.Logging;
|
|
|
|
|
//using System;
|
|
|
|
|
//using System.Collections.Generic;
|
|
|
|
|
//using System.Linq;
|
|
|
|
|
//using System.Net.Http;
|
|
|
|
|
|
|
|
|
|
namespace Platform.Apis.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
|
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class SiteController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfiguration _cfg;
|
|
|
|
|
private readonly ILogger<OrganController> _logger;
|
|
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
|
private readonly IRepository<IoTTimer> _organSceneTimerRepo;
|
|
|
|
|
private readonly ISettingService _settingService;
|
|
|
|
|
private readonly IRepository<OrganUser> _userRepo;
|
|
|
|
|
//namespace Platform.Apis.Controllers
|
|
|
|
|
//{
|
|
|
|
|
// [ApiVersion("1.0")]
|
|
|
|
|
// [Route("api/v{version:apiVersion}/[controller]/[action]")]
|
|
|
|
|
// [ApiController]
|
|
|
|
|
// public class SiteController : ControllerBase
|
|
|
|
|
// {
|
|
|
|
|
// private readonly IConfiguration _cfg;
|
|
|
|
|
// private readonly ILogger<OrganController> _logger;
|
|
|
|
|
// private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
|
// private readonly IRepository<IoTTimer> _organSceneTimerRepo;
|
|
|
|
|
// private readonly ISettingService _settingService;
|
|
|
|
|
// private readonly IRepository<OrganUser> _userRepo;
|
|
|
|
|
|
|
|
|
|
public SiteController(IConfiguration cfg,
|
|
|
|
|
IHttpClientFactory httpClientFactory,
|
|
|
|
|
IRepository<IoTTimer> organSceneTimerRepo,
|
|
|
|
|
ILogger<OrganController> logger,
|
|
|
|
|
ISettingService settingService,
|
|
|
|
|
IRepository<OrganUser> userRepo)
|
|
|
|
|
{
|
|
|
|
|
this._cfg = cfg;
|
|
|
|
|
this._httpClientFactory = httpClientFactory;
|
|
|
|
|
this._organSceneTimerRepo = organSceneTimerRepo;
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
this._settingService = settingService;
|
|
|
|
|
this._userRepo = userRepo;
|
|
|
|
|
}
|
|
|
|
|
// public SiteController(IConfiguration cfg,
|
|
|
|
|
// IHttpClientFactory httpClientFactory,
|
|
|
|
|
// IRepository<IoTTimer> organSceneTimerRepo,
|
|
|
|
|
// ILogger<OrganController> logger,
|
|
|
|
|
// ISettingService settingService,
|
|
|
|
|
// IRepository<OrganUser> userRepo)
|
|
|
|
|
// {
|
|
|
|
|
// this._cfg = cfg;
|
|
|
|
|
// this._httpClientFactory = httpClientFactory;
|
|
|
|
|
// this._organSceneTimerRepo = organSceneTimerRepo;
|
|
|
|
|
// this._logger = logger;
|
|
|
|
|
// this._settingService = settingService;
|
|
|
|
|
// this._userRepo = userRepo;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult GetSite(Guid? organId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var username = User.Identity.IsAuthenticated ? this.HttpContext.User.Identity.Name : null;
|
|
|
|
|
var roles = new List<string>();
|
|
|
|
|
var permissions = new List<string>();
|
|
|
|
|
if (User.Identity.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
roles = this._userRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.User.UserName == username)
|
|
|
|
|
.WhereIf(organId.HasValue,o=>o.OrganId==organId.Value)
|
|
|
|
|
.SelectMany(o => o.UserRoles)
|
|
|
|
|
.Select(o => o.OrganRole.Name)
|
|
|
|
|
.ToList();
|
|
|
|
|
permissions = this._userRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.User.UserName == username)
|
|
|
|
|
.WhereIf(organId.HasValue, o => o.OrganId == organId.Value)
|
|
|
|
|
.SelectMany(o => o.UserRoles)
|
|
|
|
|
.Select(o => o.OrganRole)
|
|
|
|
|
.SelectMany(o => o.RolePermissions)
|
|
|
|
|
.Select(o => o.Permission)
|
|
|
|
|
.Select(o => o.Number)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
return Ok(new
|
|
|
|
|
{
|
|
|
|
|
logo = this._settingService.GetValue("logo"),
|
|
|
|
|
name = this._settingService.GetValue("name"),
|
|
|
|
|
copyright = this._settingService.GetValue("copyright"),
|
|
|
|
|
version = Helper.Instance.GetVersion(),
|
|
|
|
|
username,
|
|
|
|
|
roles,
|
|
|
|
|
permissions,
|
|
|
|
|
sso = this._settingService.GetValue("sso")
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this._logger.LogError(ex, ex.Message);
|
|
|
|
|
return Problem(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// [HttpPost]
|
|
|
|
|
// public IActionResult GetSite(Guid? organId)
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// var username = User.Identity.IsAuthenticated ? this.HttpContext.User.Identity.Name : null;
|
|
|
|
|
// var roles = new List<string>();
|
|
|
|
|
// var permissions = new List<string>();
|
|
|
|
|
// if (User.Identity.IsAuthenticated)
|
|
|
|
|
// {
|
|
|
|
|
// roles = this._userRepo.ReadOnlyTable()
|
|
|
|
|
// .Where(o => o.User.UserName == username)
|
|
|
|
|
// .WhereIf(organId.HasValue,o=>o.OrganId==organId.Value)
|
|
|
|
|
// .SelectMany(o => o.UserRoles)
|
|
|
|
|
// .Select(o => o.OrganRole.Name)
|
|
|
|
|
// .ToList();
|
|
|
|
|
// permissions = this._userRepo.ReadOnlyTable()
|
|
|
|
|
// .Where(o => o.User.UserName == username)
|
|
|
|
|
// .WhereIf(organId.HasValue, o => o.OrganId == organId.Value)
|
|
|
|
|
// .SelectMany(o => o.UserRoles)
|
|
|
|
|
// .Select(o => o.OrganRole)
|
|
|
|
|
// .SelectMany(o => o.RolePermissions)
|
|
|
|
|
// .Select(o => o.Permission)
|
|
|
|
|
// .Select(o => o.Number)
|
|
|
|
|
// .ToList();
|
|
|
|
|
// }
|
|
|
|
|
// return Ok(new
|
|
|
|
|
// {
|
|
|
|
|
// logo = this._settingService.GetValue("logo"),
|
|
|
|
|
// name = this._settingService.GetValue("name"),
|
|
|
|
|
// copyright = this._settingService.GetValue("copyright"),
|
|
|
|
|
// version = Helper.Instance.GetVersion(),
|
|
|
|
|
// username,
|
|
|
|
|
// roles,
|
|
|
|
|
// permissions,
|
|
|
|
|
// sso = this._settingService.GetValue("sso")
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// this._logger.LogError(ex, ex.Message);
|
|
|
|
|
// return Problem(ex.Message);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|