添加项目文件。
This commit is contained in:
1 parent
05e131ca4e
commit
514d6f5255
1162 files changed
+81255
No files matched your search
@@ -0,0 +1,339 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Core.Support.Json;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ApiController]
|
||||
[Route("api/_[controller]")]
|
||||
[ActionDescription("_Admin.LoginApi")]
|
||||
[AllRights]
|
||||
public class AccountController : BaseApiController
|
||||
{
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> Login([FromForm] string account, [FromForm] string password, [FromForm] string tenant = null, [FromForm] bool rememberLogin = false)
|
||||
{
|
||||
|
||||
var user = Wtm.DoLogin(account, password, tenant);
|
||||
if (user == null)
|
||||
{
|
||||
return BadRequest(Localizer["Sys.LoginFailed"].Value);
|
||||
}
|
||||
|
||||
//其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值
|
||||
|
||||
Wtm.LoginUserInfo = user;
|
||||
|
||||
AuthenticationProperties properties = null;
|
||||
if (rememberLogin)
|
||||
{
|
||||
properties = new AuthenticationProperties
|
||||
{
|
||||
IsPersistent = true,
|
||||
ExpiresUtc = DateTimeOffset.UtcNow.Add(TimeSpan.FromDays(30))
|
||||
};
|
||||
}
|
||||
|
||||
var principal = Wtm.LoginUserInfo.CreatePrincipal();
|
||||
await Wtm.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, properties);
|
||||
return CheckUserInfo();
|
||||
}
|
||||
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> LoginJwt(SimpleLogin loginInfo)
|
||||
{
|
||||
var user = Wtm.DoLogin(loginInfo.Account, loginInfo.Password, loginInfo.Tenant);
|
||||
if (user == null)
|
||||
{
|
||||
ModelState.AddModelError(" ", Localizer["Sys.LoginFailed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
|
||||
//其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值
|
||||
|
||||
Wtm.LoginUserInfo = user;
|
||||
var authService = HttpContext.RequestServices.GetService(typeof(ITokenService)) as ITokenService;
|
||||
var token = await authService.IssueTokenAsync(Wtm.LoginUserInfo);
|
||||
return Content(JsonSerializer.Serialize(token), "application/json");
|
||||
}
|
||||
|
||||
[Public]
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> LoginRemote([FromQuery] string _remotetoken)
|
||||
{
|
||||
if (Wtm?.LoginUserInfo != null)
|
||||
{
|
||||
var principal = Wtm.LoginUserInfo.CreatePrincipal();
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, null);
|
||||
}
|
||||
return CheckUserInfo();
|
||||
}
|
||||
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult SetTenant([FromQuery] string tenant)
|
||||
{
|
||||
bool rv = Wtm.SetCurrentTenant(tenant == "" ? null : tenant);
|
||||
return Ok(rv);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Reg(SimpleReg regInfo)
|
||||
{
|
||||
var exist = DC.Set<FrameworkUser>().Any(x => x.ITCode.ToLower() == regInfo.ITCode.ToLower());
|
||||
|
||||
if (exist == true)
|
||||
{
|
||||
ModelState.AddModelError("ITCode", Localizer["Login.ItcodeDuplicate"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
|
||||
var hasuserrole = DC.Set<FrameworkRole>().Where(x => x.RoleCode == "002").FirstOrDefault();
|
||||
FrameworkUser user = new FrameworkUser
|
||||
{
|
||||
ITCode = regInfo.ITCode,
|
||||
Name = regInfo.Name,
|
||||
Password = Utils.GetMD5String(regInfo.Password),
|
||||
IsValid = true,
|
||||
PhotoId = regInfo.PhotoId,
|
||||
};
|
||||
if (hasuserrole != null)
|
||||
{
|
||||
var userrole = new FrameworkUserRole
|
||||
{
|
||||
UserCode = user.ITCode,
|
||||
RoleCode = "002"
|
||||
};
|
||||
DC.Set<FrameworkUserRole>().Add(userrole);
|
||||
}
|
||||
DC.Set<FrameworkUser>().Add(user);
|
||||
DC.SaveChanges();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("[action]")]
|
||||
[AllRights]
|
||||
[ProducesResponseType(typeof(Token), StatusCodes.Status200OK)]
|
||||
public IActionResult RefreshToken(string refreshToken)
|
||||
{
|
||||
var rv = Wtm.RefreshToken();
|
||||
if (rv == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(rv);
|
||||
}
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult CheckUserInfo(bool IsApi = true)
|
||||
{
|
||||
if (Wtm.LoginUserInfo == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
var forapi = Wtm.LoginUserInfo;
|
||||
if (IsApi)
|
||||
{
|
||||
forapi.SetAttributesForApi(Wtm);
|
||||
}
|
||||
forapi.DataPrivileges = null;
|
||||
forapi.FunctionPrivileges = null;
|
||||
if (forapi.Attributes == null)
|
||||
{
|
||||
forapi.Attributes = new Dictionary<string, object>();
|
||||
}
|
||||
if (forapi.Attributes.ContainsKey("IsMainHost"))
|
||||
{
|
||||
forapi.Attributes.Remove("IsMainHost");
|
||||
}
|
||||
if (ConfigInfo.HasMainHost && string.IsNullOrEmpty(Wtm.LoginUserInfo.TenantCode) == true)
|
||||
{
|
||||
forapi.Attributes.Add("IsMainHost", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
forapi.Attributes.Add("IsMainHost", false);
|
||||
}
|
||||
return Ok(forapi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[AllRights]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ChangePassword(ChangePasswordVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm).Result;
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoChange();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Public]
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> Logout()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
await Wtm.CallAPI<string>("mainhost", "/api/_account/logout", HttpMethodEnum.GET, new { }, 10);
|
||||
return Ok(ConfigInfo.MainHost);
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpContext.Session.Clear();
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
return Ok("/");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetFrameworkRoles")]
|
||||
[ActionDescription("GetRoles")]
|
||||
[AllRights]
|
||||
public IActionResult GetFrameworkRoles()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_account/GetFrameworkRoles").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkRole>().GetSelectListItems(Wtm, x => x.RoleName, x => x.RoleCode));
|
||||
}
|
||||
|
||||
[HttpGet("GetFrameworkGroups")]
|
||||
[ActionDescription("GetGroups")]
|
||||
[AllRights]
|
||||
public IActionResult GetFrameworkGroups()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_account/GetFrameworkGroups").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, x => x.GroupName, x => x.GroupCode));
|
||||
}
|
||||
|
||||
[HttpGet("GetFrameworkGroupsTree")]
|
||||
[ActionDescription("GetGroupsTree")]
|
||||
[AllRights]
|
||||
public IActionResult GetFrameworkGroupsTree()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_account/GetFrameworkGroupsTree").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkGroup>().GetTreeSelectListItems(Wtm, x => x.GroupName, x => x.GroupCode));
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("GetUserById")]
|
||||
[AllRights]
|
||||
public IActionResult GetUserById(string keywords)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_account/GetUserById").Result;
|
||||
}
|
||||
var users = DC.Set<FrameworkUser>().Where(x => x.ITCode.ToLower().StartsWith(keywords.ToLower())).GetSelectListItems(Wtm, x => x.Name + "(" + x.ITCode + ")", x => x.ITCode);
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("GetUserByGroup")]
|
||||
[AllRights]
|
||||
public IActionResult GetUserByGroup(string keywords)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_account/GetUserByGroup").Result;
|
||||
}
|
||||
var users = DC.Set<FrameworkUserGroup>().Where(x => x.GroupCode == keywords).Select(x => x.UserCode).ToList();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("GetUserByRole")]
|
||||
[AllRights]
|
||||
public IActionResult GetUserByRole(string keywords)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_account/GetUserByRole").Result;
|
||||
}
|
||||
var users = DC.Set<FrameworkUserRole>().Where(x => x.RoleCode == keywords).Select(x => x.UserCode).ToList();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SimpleLogin
|
||||
{
|
||||
public string Account { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Tenant { get; set; }
|
||||
|
||||
public string RemoteToken { get; set; }
|
||||
}
|
||||
public class SimpleReg
|
||||
{
|
||||
[Display(Name = "_Admin.Account")]
|
||||
[Required(ErrorMessage = "Validate.{0}required")]
|
||||
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
|
||||
public string ITCode { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.Name")]
|
||||
[Required(ErrorMessage = "Validate.{0}required")]
|
||||
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Display(Name = "Login.Password")]
|
||||
[Required(AllowEmptyStrings = false)]
|
||||
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.Photo")]
|
||||
public Guid? PhotoId { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.ActionLogVMs;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ActionDescription("MenuKey.ActionLog")]
|
||||
[ApiController]
|
||||
[Route("api/_[controller]")]
|
||||
public class ActionLogController : BaseApiController
|
||||
{
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Search(ActionLogSearcher searcher)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<ActionLogListVM>(passInit:true);
|
||||
vm.Searcher = searcher;
|
||||
return Content(vm.GetJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Get")]
|
||||
[HttpGet("{id}")]
|
||||
public ActionLogVM Get(Guid id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<ActionLogVM>(id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
[HttpPost("[action]")]
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public IActionResult BatchDelete(string[] ids)
|
||||
{
|
||||
var vm = Wtm.CreateVM<ActionLogBatchVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(ids.Count());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[ActionDescription("Sys.Export")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcel(ActionLogSearcher searcher)
|
||||
{
|
||||
var vm = Wtm.CreateVM<ActionLogListVM>();
|
||||
vm.Searcher = searcher;
|
||||
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.ExportByIds")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcelByIds(string[] ids)
|
||||
{
|
||||
var vm = Wtm.CreateVM<ActionLogListVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = new List<string>(ids);
|
||||
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
||||
}
|
||||
return vm.GetExportData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.DataPrivilegeVMs;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ActionDescription("MenuKey.DataPrivilege")]
|
||||
[ApiController]
|
||||
[Route("api/_[controller]")]
|
||||
public class DataPrivilegeController : BaseApiController
|
||||
{
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost("[action]")]
|
||||
public ActionResult Search(DataPrivilegeSearcher searcher)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<DataPrivilegeListVM>(passInit: true);
|
||||
vm.Searcher = searcher;
|
||||
return Content(vm.GetJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Get")]
|
||||
[HttpGet("[action]")]
|
||||
public DataPrivilegeVM Get(string TableName, string TargetId, DpTypeEnum DpType)
|
||||
{
|
||||
DataPrivilegeVM vm = null;
|
||||
if (DpType == DpTypeEnum.User)
|
||||
{
|
||||
vm = Wtm.CreateVM<DataPrivilegeVM>(values: x => x.Entity.TableName == TableName && x.Entity.UserCode == TargetId && x.DpType == DpType);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm = Wtm.CreateVM<DataPrivilegeVM>(values: x => x.Entity.TableName == TableName && x.Entity.GroupCode == TargetId && x.DpType == DpType);
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> Add(DataPrivilegeVM vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
await vm.DoAddAsync();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPut("[action]")]
|
||||
public async Task<IActionResult> Edit(DataPrivilegeVM vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
await vm.DoEditAsync(false);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("[action]")]
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public async Task<ActionResult> Delete(SimpleDpModel dp)
|
||||
{
|
||||
DataPrivilegeVM vm = null;
|
||||
if (dp.Type == DpTypeEnum.User)
|
||||
{
|
||||
vm = Wtm.CreateVM<DataPrivilegeVM>(values: x => x.Entity.TableName == dp.ModelName && x.Entity.UserCode == dp.Id && x.DpType == dp.Type);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm = Wtm.CreateVM<DataPrivilegeVM>(values: x => x.Entity.TableName == dp.ModelName && x.Entity.GroupCode == dp.Id && x.DpType == dp.Type);
|
||||
}
|
||||
await vm.DoDeleteAsync();
|
||||
return Ok(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public ActionResult GetPrivilegeByTableName(string table)
|
||||
{
|
||||
var AllItems = new List<ComboSelectListItem>();
|
||||
var dps =Wtm.DataPrivilegeSettings.Where(x => x.ModelName == table).SingleOrDefault();
|
||||
if (dps != null)
|
||||
{
|
||||
AllItems = dps.GetItemList(Wtm);
|
||||
}
|
||||
return Ok(AllItems);
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public ActionResult GetPrivileges()
|
||||
{
|
||||
var rv = Wtm.DataPrivilegeSettings.ToListItems(x => x.PrivillegeName, x => x.ModelName);
|
||||
return Ok(rv);
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetUserGroups()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_DataPrivilege/GetUserGroups").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, x => x.GroupName, x => x.GroupCode));
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetUserGroupsTree()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_DataPrivilege/GetUserGroupsTree").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkGroup>().GetTreeSelectListItems(Wtm, x => x.GroupName, x => x.GroupCode));
|
||||
}
|
||||
}
|
||||
|
||||
public class SimpleDpModel
|
||||
{
|
||||
public string ModelName { get; set; }
|
||||
public string Id { get; set; }
|
||||
public DpTypeEnum Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.IO;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Support.FileHandlers;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ApiController]
|
||||
[Route("api/_file")]
|
||||
[AllRights]
|
||||
[ActionDescription("_Admin.FileApi")]
|
||||
public class FileApiController : BaseApiController
|
||||
{
|
||||
[HttpPost("[action]")]
|
||||
[ActionDescription("UploadFile")]
|
||||
public IActionResult Upload([FromServices] WtmFileProvider fp, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
|
||||
{
|
||||
var FileData = Request.Form.Files[0];
|
||||
var file = fp.Upload(FileData.FileName, FileData.Length, FileData.OpenReadStream(), groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));
|
||||
return Ok(new { Id = file.GetID(), Name = file.FileName });
|
||||
}
|
||||
|
||||
[HttpPost("[action]")]
|
||||
[ActionDescription("UploadPic")]
|
||||
public IActionResult UploadImage([FromServices] WtmFileProvider fp, int? width = null, int? height = null, string sm = null, string groupName = null, string subdir = null, string extra = null, string csName = null)
|
||||
{
|
||||
if (width == null && height == null)
|
||||
{
|
||||
return Upload(fp, sm, groupName, csName);
|
||||
}
|
||||
var FileData = Request.Form.Files[0];
|
||||
|
||||
Image oimage = Image.Load(FileData.OpenReadStream());
|
||||
if (oimage == null)
|
||||
{
|
||||
return BadRequest(Localizer["Sys.UploadFailed"]);
|
||||
}
|
||||
if (width == null)
|
||||
{
|
||||
width = height * oimage.Width / oimage.Height;
|
||||
}
|
||||
if (height == null)
|
||||
{
|
||||
height = width * oimage.Height / oimage.Width;
|
||||
}
|
||||
MemoryStream ms = new MemoryStream();
|
||||
oimage.Mutate(x => x.Resize(width.Value, height.Value));
|
||||
oimage.SaveAsJpeg(ms);
|
||||
ms.Position = 0;
|
||||
var file = fp.Upload(FileData.FileName, FileData.Length, ms, groupName, subdir, extra, sm, Wtm.CreateDC(cskey: csName));
|
||||
oimage.Dispose();
|
||||
ms.Dispose();
|
||||
|
||||
if (file != null)
|
||||
{
|
||||
return Ok(new { Id = file.GetID(), Name = file.FileName });
|
||||
}
|
||||
return BadRequest(Localizer["Sys.UploadFailed"]);
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("[action]/{id}")]
|
||||
[ActionDescription("GetFileName")]
|
||||
[Public]
|
||||
public IActionResult GetFileName([FromServices] WtmFileProvider fp, string id, string csName = null)
|
||||
{
|
||||
return Ok(fp.GetFileName(id, Wtm.CreateDC(cskey: csName)));
|
||||
}
|
||||
|
||||
[HttpGet("[action]/{id}")]
|
||||
[ActionDescription("GetFile")]
|
||||
[Public]
|
||||
public async Task<IActionResult> GetFile([FromServices] WtmFileProvider fp, string id, string csName = null, int? width = null, int? height = null)
|
||||
{
|
||||
var file = fp.GetFile(id, true, Wtm.CreateDC(cskey: csName));
|
||||
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
return BadRequest(Localizer["Sys.FileNotFound"]);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (width != null || height != null)
|
||||
{
|
||||
Image oimage = Image.Load(file.DataStream);
|
||||
if (oimage != null)
|
||||
{
|
||||
if (width == null)
|
||||
{
|
||||
width = oimage.Width * height / oimage.Height;
|
||||
}
|
||||
if (height == null)
|
||||
{
|
||||
height = oimage.Height * width / oimage.Width;
|
||||
}
|
||||
var ms = new MemoryStream();
|
||||
oimage.Mutate(x => x.Resize(width.Value, height.Value));
|
||||
oimage.SaveAsJpeg(ms);
|
||||
ms.Position = 0;
|
||||
await ms?.CopyToAsync(Response.Body);
|
||||
file.DataStream.Dispose();
|
||||
ms.Dispose();
|
||||
oimage.Dispose();
|
||||
return new EmptyResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
var ext = file.FileExt.ToLower();
|
||||
if (ext == "mp4")
|
||||
{
|
||||
return File(file.DataStream, "video/mpeg4", enableRangeProcessing: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await file.DataStream?.CopyToAsync(Response.Body);
|
||||
file.DataStream.Dispose();
|
||||
return new EmptyResult();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("[action]/{id}")]
|
||||
[ActionDescription("GetFileName")]
|
||||
[Public]
|
||||
public IActionResult GetFileInfo([FromServices] WtmFileProvider fp, string id, string csName = null)
|
||||
{
|
||||
FileAttachment rv = new FileAttachment();
|
||||
using (var dc = Wtm.CreateDC(cskey: csName))
|
||||
{
|
||||
rv = dc.Set<FileAttachment>().CheckID(id).FirstOrDefault();
|
||||
}
|
||||
return Ok(rv);
|
||||
}
|
||||
|
||||
[HttpGet("[action]/{id}")]
|
||||
[ActionDescription("GetUserPhoto")]
|
||||
[Public]
|
||||
public async Task<IActionResult> GetUserPhoto([FromServices] WtmFileProvider fp, string id, string csName = null, int? width = null, int? height = null)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Redirect(Wtm.ConfigInfo.MainHost+ Request.Path);
|
||||
}
|
||||
return await this.GetFile(fp,id, csName, width, height);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("[action]/{id}")]
|
||||
[ActionDescription("DownloadFile")]
|
||||
[Public]
|
||||
public IActionResult DownloadFile([FromServices] WtmFileProvider fp, string id, string csName = null)
|
||||
{
|
||||
var file = fp.GetFile(id, true, Wtm.CreateDC(cskey:csName));
|
||||
if (file == null)
|
||||
{
|
||||
return BadRequest(Localizer["Sys.FileNotFound"]);
|
||||
}
|
||||
var ext = file.FileExt.ToLower();
|
||||
var provider = new FileExtensionContentTypeProvider();
|
||||
string contentType;
|
||||
if (!provider.TryGetContentType(file.FileName, out contentType))
|
||||
{
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
return File(file.DataStream, contentType, file.FileName ?? (Guid.NewGuid().ToString() + ext));
|
||||
}
|
||||
|
||||
[HttpGet("[action]/{id}")]
|
||||
[ActionDescription("DeleteFile")]
|
||||
public IActionResult DeletedFile([FromServices] WtmFileProvider fp, string id, string csName = null)
|
||||
{
|
||||
fp.DeleteFile(id, Wtm.CreateDC(cskey: csName));
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkGroupVMs;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ActionDescription("MenuKey.GroupManagement")]
|
||||
[ApiController]
|
||||
[Route("api/_[controller]")]
|
||||
public class FrameworkGroupController : BaseApiController
|
||||
{
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Search(FrameworkGroupSearcher searcher)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm).Result;
|
||||
}
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkGroupListVM>(passInit: true);
|
||||
vm.Searcher = searcher;
|
||||
return Content(vm.GetJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Get")]
|
||||
[HttpGet("{id}")]
|
||||
public FrameworkGroupVM Get(Guid id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkGroupVM>(id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Add(FrameworkGroupVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoAdd();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPut("[action]")]
|
||||
public IActionResult Edit(FrameworkGroupVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoEdit(false);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("BatchDelete")]
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public async Task<IActionResult> BatchDelete(string[] ids)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkGroupBatchVM>();
|
||||
List<string> GroupCode = new List<string>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
GroupCode = DC.Set<FrameworkGroup>().CheckIDs(new List<string>(ids)).Select(x => x.GroupCode).ToList();
|
||||
vm.Ids = ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
var gr = DC.Set<FrameworkUserGroup>().Where(x => GroupCode.Contains(x.GroupCode)).ToList();
|
||||
var itcodes = gr.Select(x => x.UserCode).ToArray();
|
||||
DC.Set<FrameworkUserGroup>().RemoveRange(gr);
|
||||
DC.SaveChanges();
|
||||
await Wtm.RemoveUserCacheByGroup(GroupCode.ToArray());
|
||||
Wtm.RemoveGroupCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
|
||||
return Ok(ids.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Export")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcel(FrameworkGroupSearcher searcher)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkGroupListVM>();
|
||||
vm.Searcher = searcher;
|
||||
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.ExportByIds")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcelByIds(string[] ids)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkGroupListVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = new List<string>(ids);
|
||||
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
||||
}
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.DownloadTemplate")]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetExcelTemplate()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkGroupImportVM>();
|
||||
var qs = new Dictionary<string, string>();
|
||||
foreach (var item in Request.Query.Keys)
|
||||
{
|
||||
qs.Add(item, Request.Query[item]);
|
||||
}
|
||||
vm.SetParms(qs);
|
||||
var data = vm.GenerateTemplate(out string fileName);
|
||||
return File(data, "application/vnd.ms-excel", fileName);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Import")]
|
||||
[HttpPost("[action]")]
|
||||
public ActionResult Import(FrameworkGroupImportVM vm)
|
||||
{
|
||||
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
||||
{
|
||||
return BadRequest(vm.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
Wtm.RemoveGroupCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
|
||||
return Ok(vm.EntityList.Count);
|
||||
}
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetParents()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkgroup/GetParents").Result;
|
||||
}
|
||||
var data = DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, x => x.GroupName);
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetParentsTree()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkgroup/GetParentsTree").Result;
|
||||
}
|
||||
var data = DC.Set<FrameworkGroup>().GetTreeSelectListItems(Wtm, x => x.GroupName);
|
||||
return Ok(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Core.Support.Json;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ActionDescription("MenuKey.MenuMangement")]
|
||||
[ApiController]
|
||||
[Route("api/_[controller]")]
|
||||
[MainTenantOnly]
|
||||
public class FrameworkMenuController : BaseApiController
|
||||
{
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost("[action]")]
|
||||
public ActionResult Search(BaseSearcher searcher)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkMenuListVM2>(passInit: true);
|
||||
vm.Searcher = searcher;
|
||||
return Content(vm.GetJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Get")]
|
||||
[HttpGet("{id}")]
|
||||
public FrameworkMenuVM2 Get(Guid id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkMenuVM2>(id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Add(FrameworkMenuVM2 vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoAdd();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPut("[action]")]
|
||||
public IActionResult Edit(FrameworkMenuVM2 vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoEdit(true);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("BatchDelete")]
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public IActionResult BatchDelete(string[] ids)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkMenuBatchVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(ids.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Export")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcel(BaseSearcher searcher)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkMenuListVM2>();
|
||||
vm.Searcher = searcher;
|
||||
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.ExportByIds")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcelByIds(string[] ids)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkMenuListVM2>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = new List<string>(ids);
|
||||
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
||||
}
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("_Admin.UnsetPages")]
|
||||
[HttpGet("[action]")]
|
||||
public string UnsetPages()
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkActionListVM>();
|
||||
return vm.GetJson();
|
||||
}
|
||||
|
||||
[ActionDescription("_Admin.RefreshMenu")]
|
||||
[HttpGet("[action]")]
|
||||
public ActionResult RefreshMenu()
|
||||
{
|
||||
Cache.Delete(nameof(GlobalData.AllMenus));
|
||||
return Ok(Localizer["Sys.OprationSuccess"].Value);
|
||||
}
|
||||
|
||||
[ActionDescription("GetActionsByModelId")]
|
||||
[HttpGet("GetActionsByModel")]
|
||||
[AllRights]
|
||||
public ActionResult GetActionsByModel(string ModelName)
|
||||
{
|
||||
var m = GlobaInfo.AllModule.Where(x => x.IsApi == true && x.FullName.ToLower() == ModelName.ToLower()).SelectMany(x => x.Actions).ToList();
|
||||
List<SimpleAction> toremove = new List<SimpleAction>();
|
||||
foreach (var item in m)
|
||||
{
|
||||
if (item.IgnorePrivillege == true || item.Module.IgnorePrivillege == true)
|
||||
{
|
||||
toremove.Add(item);
|
||||
}
|
||||
}
|
||||
toremove.ForEach(x => m.Remove(x));
|
||||
var actions = m.ToListItems(y => y.ActionName, y => y.MethodName);
|
||||
actions.ForEach(x => x.Selected = true);
|
||||
return Ok(actions);
|
||||
}
|
||||
|
||||
[ActionDescription("GetFolders")]
|
||||
[HttpGet("GetFolders")]
|
||||
[AllRights]
|
||||
public ActionResult GetFolders()
|
||||
{
|
||||
var AllParents = DC.Set<FrameworkMenu>().Where(x => x.FolderOnly == true).OrderBy(x => x.DisplayOrder).GetSelectListItems(Wtm, x => x.PageName);
|
||||
foreach (var p in AllParents)
|
||||
{
|
||||
if (p.Text.StartsWith("MenuKey."))
|
||||
{
|
||||
p.Text = Localizer[p.Text];
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(AllParents);
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("GetIcons")]
|
||||
public List<ComboSelectListItem> GetIcons()
|
||||
{
|
||||
return IconFontsHelper.IconFontItems;
|
||||
}
|
||||
|
||||
[AllRights]
|
||||
[HttpGet("GetIconItems")]
|
||||
public List<MenuItem> GetIconItems(string key)
|
||||
{
|
||||
return IconFontsHelper.IconFontDicItems[key];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ActionDescription("MenuKey.RoleManagement")]
|
||||
[ApiController]
|
||||
[Route("api/_[controller]")]
|
||||
public class FrameworkRoleController : BaseApiController
|
||||
{
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Search(FrameworkRoleSearcher searcher)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm).Result;
|
||||
}
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkRoleListVM>(passInit: true);
|
||||
vm.Searcher = searcher;
|
||||
return Content(vm.GetJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Get")]
|
||||
[HttpGet("{id}")]
|
||||
public FrameworkRoleVM Get(Guid id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkRoleVM>(id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
[ActionDescription("GetPageActions")]
|
||||
[HttpGet("[action]/{id}")]
|
||||
[AllRights]
|
||||
public FrameworkRoleMDVM2 GetPageActions(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkRoleMDVM2>(id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
[ActionDescription("_Admin.PageFunction")]
|
||||
[HttpPut("[action]")]
|
||||
public async Task<IActionResult> EditPrivilege(FrameworkRoleMDVM2 vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
await vm.DoChangeAsync();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Add(FrameworkRoleVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoAdd();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPut("[action]")]
|
||||
public IActionResult Edit(FrameworkRoleVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoEdit(false);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("BatchDelete")]
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public async Task<IActionResult> BatchDelete(string[] ids)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkRoleBatchVM>();
|
||||
List<string> RoleCode = new List<string>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
RoleCode = DC.Set<FrameworkRole>().CheckIDs(new List<string>(ids)).Select(x => x.RoleCode).ToList();
|
||||
vm.Ids = ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
var ur = DC.Set<FrameworkUserRole>().Where(x => RoleCode.Contains(x.RoleCode)).ToList();
|
||||
var itcodes = ur.Select(x => x.UserCode).ToArray();
|
||||
DC.Set<FrameworkUserRole>().RemoveRange(ur);
|
||||
DC.SaveChanges();
|
||||
await Wtm.RemoveUserCacheByRole(itcodes);
|
||||
await Wtm.RemoveRoleCache(Wtm.LoginUserInfo.CurrentTenant);
|
||||
return Ok(ids.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Export")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcel(FrameworkRoleSearcher searcher)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkRoleListVM>();
|
||||
vm.Searcher = searcher;
|
||||
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.ExportByIds")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcelByIds(string[] ids)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkRoleListVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = new List<string>(ids);
|
||||
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
||||
}
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.DownloadTemplate")]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetExcelTemplate()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkRoleImportVM>();
|
||||
var qs = new Dictionary<string, string>();
|
||||
foreach (var item in Request.Query.Keys)
|
||||
{
|
||||
qs.Add(item, Request.Query[item]);
|
||||
}
|
||||
vm.SetParms(qs);
|
||||
var data = vm.GenerateTemplate(out string fileName);
|
||||
return File(data, "application/vnd.ms-excel", fileName);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Import")]
|
||||
[HttpPost("[action]")]
|
||||
public ActionResult Import(FrameworkRoleImportVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
|
||||
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
||||
{
|
||||
return BadRequest(vm.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
Wtm.RemoveRoleCache(Wtm.LoginUserInfo.CurrentTenant).Wait();
|
||||
return Ok(vm.EntityList.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkTenantVMs;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ActionDescription("MenuKey.FrameworkTenant")]
|
||||
[ApiController]
|
||||
[Route("api/_[controller]")]
|
||||
[FixConnection(CsName = "default")]
|
||||
public class FrameworkTenantController : BaseApiController
|
||||
{
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Search(FrameworkTenantSearcher searcher)
|
||||
{
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkTenantListVM>(passInit: true);
|
||||
vm.Searcher = searcher;
|
||||
return Content(vm.GetJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Get")]
|
||||
[HttpGet("{id}")]
|
||||
public FrameworkTenantVM Get(Guid id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkTenantVM>(id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Add(FrameworkTenantVM vm)
|
||||
{
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoAdd();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPut("[action]")]
|
||||
public IActionResult Edit(FrameworkTenantVM vm)
|
||||
{
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoEdit(false);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("BatchDelete")]
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public IActionResult BatchDelete(string[] ids)
|
||||
{
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkTenantBatchVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = ids;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
Cache.Delete(nameof(GlobalData.AllTenant));
|
||||
return Ok(ids.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Export")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcel(FrameworkTenantSearcher searcher)
|
||||
{
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkTenantListVM>();
|
||||
vm.Searcher = searcher;
|
||||
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.ExportByIds")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcelByIds(string[] ids)
|
||||
{
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkTenantListVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = new List<string>(ids);
|
||||
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
||||
}
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.DownloadTemplate")]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetExcelTemplate()
|
||||
{
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkTenantImportVM>();
|
||||
var qs = new Dictionary<string, string>();
|
||||
foreach (var item in Request.Query.Keys)
|
||||
{
|
||||
qs.Add(item, Request.Query[item]);
|
||||
}
|
||||
vm.SetParms(qs);
|
||||
var data = vm.GenerateTemplate(out string fileName);
|
||||
return File(data, "application/vnd.ms-excel", fileName);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Import")]
|
||||
[HttpPost("[action]")]
|
||||
public ActionResult Import(FrameworkTenantImportVM vm)
|
||||
{
|
||||
|
||||
if (CanUseTenant() == false)
|
||||
{
|
||||
ModelState.Clear();
|
||||
ModelState.AddModelError(" TenantNotAllowed", Localizer["_Admin.TenantNotAllowed"]);
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
||||
{
|
||||
return BadRequest(vm.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.EntityList.Count);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetFrameworkTenants")]
|
||||
[ActionDescription("GetTenants")]
|
||||
[AllRights]
|
||||
public IActionResult GetFrameworkTenants(string parent)
|
||||
{
|
||||
if (parent == "")
|
||||
{
|
||||
parent = null;
|
||||
}
|
||||
return Ok(Wtm.GlobaInfo.AllTenant.AsQueryable().Where(x => x.TenantCode == parent).GetSelectListItems(Wtm, x => x.TName, x => x.TCode));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool CanUseTenant()
|
||||
{
|
||||
if (Wtm.LoginUserInfo != null && (Wtm.LoginUserInfo.CurrentTenant == null || Wtm.GlobaInfo.AllTenant.Any(x => x.TCode == Wtm.LoginUserInfo.CurrentTenant && x.Enabled == true && x.EnableSub == true)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkUserVms;
|
||||
|
||||
namespace WalkingTec.Mvvm.Admin.Api
|
||||
{
|
||||
[AuthorizeJwtWithCookie]
|
||||
[ActionDescription("MenuKey.UserManagement")]
|
||||
[ApiController]
|
||||
[Route("api/_FrameworkUser")]
|
||||
public class FrameworkUserController : BaseApiController
|
||||
{
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Search(FrameworkUserSearcher searcher)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm).Result;
|
||||
}
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkUserListVM>(passInit: true);
|
||||
vm.Searcher = searcher;
|
||||
return Content(vm.GetJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Get")]
|
||||
[HttpGet("{id}")]
|
||||
public FrameworkUserVM Get(Guid id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<FrameworkUserVM>(id);
|
||||
return vm;
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> Add(FrameworkUserVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
await vm.DoAddAsync();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPut("[action]")]
|
||||
public async Task<IActionResult> Edit(FrameworkUserVM vm)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
ModelState.Remove("Entity.Password");
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
await vm.DoEditAsync(false);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("BatchDelete")]
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public async Task<IActionResult> BatchDelete(string[] ids)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkUserBatchVM>();
|
||||
List<string> itcode = new List<string>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = ids;
|
||||
itcode = DC.Set<FrameworkUser>().CheckIDs(new List<string>(ids)).Select(x => x.ITCode).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var tran = DC.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
var ur = DC.Set<FrameworkUserRole>().Where(x => itcode.Contains(x.UserCode));
|
||||
DC.Set<FrameworkUserRole>().RemoveRange(ur);
|
||||
var ug = DC.Set<FrameworkUserGroup>().Where(x => itcode.Contains(x.UserCode));
|
||||
DC.Set<FrameworkUserGroup>().RemoveRange(ug);
|
||||
DC.SaveChanges();
|
||||
tran.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
tran.Rollback();
|
||||
}
|
||||
}
|
||||
|
||||
await Wtm.RemoveUserCache(itcode.ToArray());
|
||||
return Ok(ids.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Export")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcel(FrameworkUserSearcher searcher)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkUserListVM>();
|
||||
vm.Searcher = searcher;
|
||||
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.ExportByIds")]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult ExportExcelByIds(string[] ids)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkUserListVM>();
|
||||
if (ids != null && ids.Count() > 0)
|
||||
{
|
||||
vm.Ids = new List<string>(ids);
|
||||
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
||||
}
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.DownloadTemplate")]
|
||||
[HttpGet("[action]")]
|
||||
public IActionResult GetExcelTemplate()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
var vm = Wtm.CreateVM<FrameworkUserImportVM>();
|
||||
var qs = new Dictionary<string, string>();
|
||||
if (Request != null)
|
||||
{
|
||||
foreach (var item in Request.Query.Keys)
|
||||
{
|
||||
qs.Add(item, Request.Query[item]);
|
||||
}
|
||||
}
|
||||
vm.SetParms(qs);
|
||||
var data = vm.GenerateTemplate(out string fileName);
|
||||
return File(data, "application/vnd.ms-excel", fileName);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Import")]
|
||||
[HttpPost("[action]")]
|
||||
public ActionResult Import(FrameworkUserImportVM vm)
|
||||
{
|
||||
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Content(Localizer["_Admin.HasMainHost"]);
|
||||
}
|
||||
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
||||
{
|
||||
return BadRequest(vm.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.EntityList.Count);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetFrameworkRoles")]
|
||||
[ActionDescription("GetRoles")]
|
||||
[AllRights]
|
||||
public IActionResult GetFrameworkRoles()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkuser/GetFrameworkRoles").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkRole>().GetSelectListItems(Wtm, x => x.RoleName, x => x.RoleCode));
|
||||
}
|
||||
|
||||
[HttpGet("GetFrameworkGroups")]
|
||||
[ActionDescription("GetGroups")]
|
||||
[AllRights]
|
||||
public IActionResult GetFrameworkGroups()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkuser/GetFrameworkGroups").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkGroup>().GetSelectListItems(Wtm, x => x.GroupName, x => x.GroupCode));
|
||||
}
|
||||
|
||||
[HttpGet("GetFrameworkGroupsTree")]
|
||||
[ActionDescription("GetGroupsTree")]
|
||||
[AllRights]
|
||||
public IActionResult GetFrameworkGroupsTree()
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkuser/GetFrameworkGroupsTree").Result;
|
||||
}
|
||||
return Ok(DC.Set<FrameworkGroup>().GetTreeSelectListItems(Wtm, x => x.GroupName, x => x.GroupCode));
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("GetUserById")]
|
||||
[AllRights]
|
||||
public IActionResult GetUserById(string keywords)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkuser/GetUserById").Result;
|
||||
}
|
||||
var users = DC.Set<FrameworkUser>().Where(x => x.ITCode.ToLower().StartsWith(keywords.ToLower())).GetSelectListItems(Wtm, x => x.Name + "(" + x.ITCode + ")", x => x.ITCode);
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("GetUserByGroup")]
|
||||
[AllRights]
|
||||
public IActionResult GetUserByGroup(string keywords)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkuser/GetUserByGroup").Result;
|
||||
}
|
||||
var users = DC.Set<FrameworkUserGroup>().Where(x => x.GroupCode == keywords).Select(x=>x.UserCode).ToList();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("GetUserByRole")]
|
||||
[AllRights]
|
||||
public IActionResult GetUserByRole(string keywords)
|
||||
{
|
||||
if (ConfigInfo.HasMainHost && Wtm.LoginUserInfo?.CurrentTenant == null)
|
||||
{
|
||||
return Request.RedirectCall(Wtm, "/api/_frameworkuser/GetUserByRole").Result;
|
||||
}
|
||||
var users = DC.Set<FrameworkUserRole>().Where(x => x.RoleCode == keywords).Select(x => x.UserCode).ToList();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[ActionDescription("Login.ChangePassword")]
|
||||
[HttpPut("[action]")]
|
||||
public IActionResult Password(FrameworkUserVM vm)
|
||||
{
|
||||
var keys = ModelState.Keys.ToList();
|
||||
foreach (var item in keys)
|
||||
{
|
||||
if (item != "Entity.Password")
|
||||
{
|
||||
ModelState.Remove(item);
|
||||
}
|
||||
}
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.ChangePassword();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorJson());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(vm.Entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user