添加项目文件。
This commit is contained in:
1 parent
05e131ca4e
commit
514d6f5255
1162 files changed
+81255
No files matched your search
@@ -0,0 +1,111 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
|
||||
{
|
||||
public class FrameworkActionListVM : BasePagedListVM<FrameworkAction_ListView, BaseSearcher>
|
||||
{
|
||||
|
||||
public FrameworkActionListVM()
|
||||
{
|
||||
NeedPage = false;
|
||||
}
|
||||
|
||||
protected override List<GridAction> InitGridAction()
|
||||
{
|
||||
var actions = new List<GridAction>
|
||||
{
|
||||
};
|
||||
return actions;
|
||||
}
|
||||
|
||||
protected override IEnumerable<IGridColumn<FrameworkAction_ListView>> InitGridHeader()
|
||||
{
|
||||
var header = new List<GridColumn<FrameworkAction_ListView>>();
|
||||
|
||||
header.Add(this.MakeGridHeader(x => x.ModuleName, 150));
|
||||
header.Add(this.MakeGridHeader(x => x.ActionName, 150));
|
||||
header.Add(this.MakeGridHeader(x => x.ClassName, 150));
|
||||
header.Add(this.MakeGridHeader(x => x.MethodName, 150));
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询结果
|
||||
/// </summary>
|
||||
public override IOrderedQueryable<FrameworkAction_ListView> GetSearchQuery()
|
||||
{
|
||||
var newdc = DC as FrameworkContext;
|
||||
List<FrameworkAction_ListView> actions = new List<FrameworkAction_ListView>();
|
||||
var urls = newdc.BaseFrameworkMenus.Where(y => y.IsInside == true && y.FolderOnly == false).Select(y => y.Url).Distinct().ToList();
|
||||
if (ControllerName.Contains("/api") == false)
|
||||
{
|
||||
actions = Wtm.GlobaInfo.AllModule.SelectMany(x=>x.Actions)
|
||||
.Where(x => urls.Contains(x.Url) == false)
|
||||
.Select(x => new FrameworkAction_ListView
|
||||
{
|
||||
ID = x.ID,
|
||||
ModuleID = x.ModuleId,
|
||||
ModuleName = x.Module.ModuleName,
|
||||
ActionName = x.ActionName,
|
||||
ClassName = x.Module.ClassName,
|
||||
MethodName = x.MethodName,
|
||||
AreaName = x.Module.Area?.AreaName
|
||||
}).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
actions = Wtm.GlobaInfo.AllModule.SelectMany(x => x.Actions)
|
||||
.Where(x => x.Module.IsApi == true && urls.Contains(x.Url) == false)
|
||||
.Select(x => new FrameworkAction_ListView
|
||||
{
|
||||
ID = x.ID,
|
||||
ModuleID = x.ModuleId,
|
||||
ModuleName = x.Module.ModuleName,
|
||||
ActionName = x.ActionName,
|
||||
ClassName = x.Module.ClassName,
|
||||
MethodName = x.MethodName,
|
||||
AreaName = x.Module.Area?.AreaName
|
||||
}).ToList();
|
||||
|
||||
}
|
||||
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
List<FrameworkAction_ListView> toremove = new List<FrameworkAction_ListView>();
|
||||
foreach (var item in actions)
|
||||
{
|
||||
var m = modules.Where(x => x.ClassName == item.ClassName && x.Area?.AreaName == item.AreaName).FirstOrDefault();
|
||||
var a = m?.Actions.Where(x => x.MethodName == item.MethodName).FirstOrDefault();
|
||||
if(m?.IgnorePrivillege == true || a?.IgnorePrivillege == true)
|
||||
{
|
||||
toremove.Add(item);
|
||||
}
|
||||
}
|
||||
toremove.ForEach(x => actions.Remove(x));
|
||||
return actions.AsQueryable().OrderBy(x=>x.AreaName).ThenBy(x=>x.ModuleName).ThenBy(x=>x.MethodName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class FrameworkAction_ListView : BasePoco
|
||||
{
|
||||
public Guid? ModuleID { get; set; }
|
||||
|
||||
[Display(Name = "Codegen.ModuleName")]
|
||||
public string ModuleName { get; set; }
|
||||
[Display(Name = "_Admin.ActionName")]
|
||||
public string ActionName { get; set; }
|
||||
[Display(Name = "_Admin.ClassName")]
|
||||
public string ClassName { get; set; }
|
||||
[Display(Name = "_Admin.MethodName")]
|
||||
public string MethodName { get; set; }
|
||||
|
||||
public string AreaName { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
|
||||
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
|
||||
{
|
||||
public class FrameworkMenuBatchVM : BaseBatchVM<FrameworkMenu, FrameworkMenu_BatchEdit>
|
||||
{
|
||||
public FrameworkMenuBatchVM()
|
||||
{
|
||||
}
|
||||
protected override void InitVM()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool DoBatchDelete()
|
||||
{
|
||||
if (Ids != null)
|
||||
{
|
||||
foreach (var item in Ids)
|
||||
{
|
||||
FrameworkMenu f = new FrameworkMenu { ID = Guid.Parse(item) };
|
||||
DC.CascadeDelete(f);
|
||||
}
|
||||
}
|
||||
DC.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FrameworkMenu_BatchEdit : BaseVM
|
||||
{
|
||||
public List<Guid> IDs { get; set; }
|
||||
[Display(Name = "_Admin.ShowOnMenu")]
|
||||
public bool ShowOnMenu { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.ParentFolder")]
|
||||
public Guid? ParentID { get; set; }
|
||||
public List<ComboSelectListItem> AllParents { get; set; }
|
||||
[Display(Name = "_Admin.Icon")]
|
||||
public string Icon { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
|
||||
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
|
||||
{
|
||||
public class FrameworkMenuListVM : BasePagedListVM<FrameworkMenu_ListView, FrameworkMenuSearcher>
|
||||
{
|
||||
public FrameworkMenuListVM()
|
||||
{
|
||||
this.NeedPage = false;
|
||||
}
|
||||
|
||||
protected override IEnumerable<IGridColumn<FrameworkMenu_ListView>> InitGridHeader()
|
||||
{
|
||||
List<GridColumn<FrameworkMenu_ListView>> rv = new List<GridColumn<FrameworkMenu_ListView>>();
|
||||
switch (SearcherMode)
|
||||
{
|
||||
case ListVMSearchModeEnum.Batch:
|
||||
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
|
||||
this.MakeGridHeader(x => x.PageName),
|
||||
this.MakeGridHeader(x => x.ModuleName, 200),
|
||||
this.MakeGridHeader(x => x.ActionName, 150),
|
||||
});
|
||||
break;
|
||||
case ListVMSearchModeEnum.Custom1:
|
||||
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
|
||||
this.MakeGridHeader(x => x.PageName,300),
|
||||
});
|
||||
break;
|
||||
case ListVMSearchModeEnum.Custom2:
|
||||
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
|
||||
this.MakeGridHeader(x => x.PageName,200),
|
||||
this.MakeGridHeader(x => x.ParentId).SetHeader(Localizer["Sys.Operation"]).SetFormat((item, cell) => GenerateCheckBox(item)).SetAlign(GridColumnAlignEnum.Left),
|
||||
});
|
||||
break;
|
||||
default:
|
||||
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
|
||||
this.MakeGridHeader(x => x.PageName,300),
|
||||
this.MakeGridHeader(x => x.ModuleName, 150),
|
||||
this.MakeGridHeader(x => x.ShowOnMenu),
|
||||
this.MakeGridHeader(x => x.FolderOnly),
|
||||
this.MakeGridHeader(x => x.IsPublic),
|
||||
this.MakeGridHeader(x => x.TenantAllowed),
|
||||
this.MakeGridHeader(x => x.DisplayOrder),
|
||||
this.MakeGridHeader(x => x.Icon, 100).SetFormat(PhotoIdFormat),
|
||||
this.MakeGridHeaderAction(width: 270)
|
||||
});
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private object GenerateCheckBox(FrameworkMenu_ListView item)
|
||||
{
|
||||
StringBuilder rv = new StringBuilder();
|
||||
if (item.FolderOnly == false)
|
||||
{
|
||||
rv.Append($"<input do-not-use-selectall hidden lay-skin='primary' type='checkbox' title='{Localizer["Sys.All"]}'>");
|
||||
if (item.IsInside == true)
|
||||
{
|
||||
var others = item.Children?.ToList();
|
||||
rv.Append(UIService.MakeCheckBox(item.Allowed, Localizer["Sys.MainPage"], "menu_" + item.ID, "1"));
|
||||
if (others != null)
|
||||
{
|
||||
foreach (var c in others)
|
||||
{
|
||||
string actionname = "";
|
||||
if (c.ActionName != null)
|
||||
{
|
||||
actionname = Localizer[c.ActionName];
|
||||
}
|
||||
rv.Append(UIService.MakeCheckBox(c.Allowed, actionname, "menu_" + c.ID, "1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv.Append(UIService.MakeCheckBox(item.Allowed, Localizer["Sys.MainPage"], "menu_" + item.ID, "1"));
|
||||
}
|
||||
}
|
||||
|
||||
return rv.ToString();
|
||||
}
|
||||
|
||||
|
||||
protected override List<GridAction> InitGridAction()
|
||||
{
|
||||
if (SearcherMode == ListVMSearchModeEnum.Search)
|
||||
{
|
||||
return new List<GridAction>{
|
||||
this.MakeAction("FrameworkMenu", "Create",Localizer["Sys.Create"], Localizer["Sys.Create"], GridActionParameterTypesEnum.SingleIdWithNull,"_Admin").SetIconCls("layui-icon layui-icon-add-1"),
|
||||
this.MakeStandardAction("FrameworkMenu", GridActionStandardTypesEnum.Edit, "", "_Admin"),
|
||||
this.MakeStandardAction("FrameworkMenu", GridActionStandardTypesEnum.Delete, "", "_Admin"),
|
||||
this.MakeStandardAction("FrameworkMenu", GridActionStandardTypesEnum.Details, "", "_Admin"),
|
||||
this.MakeAction( "FrameworkMenu", "UnsetPages", Localizer["_Admin.CheckPage"], Localizer["_Admin.UnsetPages"],GridActionParameterTypesEnum.NoId, "_Admin").SetIconCls("layui-icon layui-icon-ok"),
|
||||
this.MakeAction("FrameworkMenu", "RefreshMenu", Localizer["_Admin.RefreshMenu"], Localizer["_Admin.RefreshMenu"], GridActionParameterTypesEnum.NoId,"_Admin").SetShowDialog(false).SetIconCls("layui-icon layui-icon-refresh"),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<GridAction>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string PhotoIdFormat(FrameworkMenu_ListView entity, object val)
|
||||
{
|
||||
if (entity.Icon != null)
|
||||
{
|
||||
return $"<i class='{entity.Icon}'></i>";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public override IOrderedQueryable<FrameworkMenu_ListView> GetSearchQuery()
|
||||
{
|
||||
List<FrameworkMenu> data = new List<FrameworkMenu>();
|
||||
using (var maindc = Wtm.CreateDC(false, "default"))
|
||||
{
|
||||
data = maindc.Set<FrameworkMenu>().ToList();
|
||||
}
|
||||
var topdata = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder).Where(x => x.IsInside == false || x.FolderOnly == true || x.Url.EndsWith("/Index") || string.IsNullOrEmpty(x.MethodName)).ToList();
|
||||
foreach (var item in topdata)
|
||||
{
|
||||
if (item.PageName?.StartsWith("MenuKey.") == true)
|
||||
{
|
||||
item.PageName = Localizer[item.PageName];
|
||||
}
|
||||
if (item.ModuleName?.StartsWith("MenuKey.") == true)
|
||||
{
|
||||
item.ModuleName = Localizer[item.ModuleName];
|
||||
}
|
||||
}
|
||||
if(Wtm.ConfigInfo.EnableTenant == true && LoginUserInfo.CurrentTenant != null)
|
||||
{
|
||||
var ct = Wtm.GlobaInfo.AllTenant.Where(x => x.TCode == LoginUserInfo.CurrentTenant).FirstOrDefault();
|
||||
for(int i = 0; i < topdata.Count; i++)
|
||||
{
|
||||
if (topdata[i].TenantAllowed == false || (topdata[i].Url != null && ct.EnableSub == false && topdata[i].Url.ToLower().Contains("frameworktenant")))
|
||||
{
|
||||
topdata.RemoveAt(i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
var hostonly = Wtm.GlobaInfo.AllMainTenantOnlyUrls;
|
||||
foreach (var au in hostonly)
|
||||
{
|
||||
if (topdata[i].Url != null && new Regex("^" + au + "[/\\?]?", RegexOptions.IgnoreCase).IsMatch(topdata[i].Url))
|
||||
{
|
||||
topdata.RemoveAt(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
topdata.ForEach((x) => { int l = x.GetLevel(); for (int i = 0; i < l; i++) { x.PageName = " " + x.PageName; } });
|
||||
if (SearcherMode == ListVMSearchModeEnum.Custom2)
|
||||
{
|
||||
var pris = DC.Set<FunctionPrivilege>()
|
||||
.Where(x => x.RoleCode == Searcher.RoleCode).ToList();
|
||||
var allowed = pris.Where(x => x.Allowed == true).Select(x => x.MenuItemId).ToList();
|
||||
var denied = pris.Where(x => x.Allowed == false).Select(x => x.MenuItemId).ToList();
|
||||
int order = 0;
|
||||
var data2 = topdata.Select(x => new FrameworkMenu_ListView
|
||||
{
|
||||
ID = x.ID,
|
||||
PageName = x.PageName,
|
||||
ModuleName = x.ModuleName,
|
||||
ActionName = x.ActionName,
|
||||
ShowOnMenu = x.ShowOnMenu,
|
||||
FolderOnly = x.FolderOnly,
|
||||
IsPublic = x.IsPublic,
|
||||
DisplayOrder = x.DisplayOrder,
|
||||
Children = x.Children?.Select(y => new FrameworkMenu_ListView
|
||||
{
|
||||
ID = y.ID,
|
||||
Allowed = allowed.Contains(y.ID),
|
||||
ActionName = y.ActionName
|
||||
}).ToList(),
|
||||
ExtraOrder = order++,
|
||||
ParentId = x.ParentId,
|
||||
IsInside = x.IsInside,
|
||||
TenantAllowed = x.TenantAllowed,
|
||||
Allowed = allowed.Contains(x.ID),
|
||||
Denied = denied.Contains(x.ID)
|
||||
}).OrderBy(x => x.ExtraOrder);
|
||||
return data2.AsQueryable() as IOrderedQueryable<FrameworkMenu_ListView>;
|
||||
}
|
||||
else
|
||||
{
|
||||
int order = 0;
|
||||
var data2 = topdata.Select(x => new FrameworkMenu_ListView
|
||||
{
|
||||
ID = x.ID,
|
||||
PageName = x.PageName,
|
||||
ModuleName = x.ModuleName,
|
||||
ActionName = x.ActionName,
|
||||
ShowOnMenu = x.ShowOnMenu,
|
||||
FolderOnly = x.FolderOnly,
|
||||
IsPublic = x.IsPublic,
|
||||
DisplayOrder = x.DisplayOrder,
|
||||
ExtraOrder = order++,
|
||||
TenantAllowed = x.TenantAllowed,
|
||||
ParentId = x.ParentId,
|
||||
Icon = x.Icon
|
||||
}).OrderBy(x => x.ExtraOrder);
|
||||
|
||||
return data2.AsQueryable() as IOrderedQueryable<FrameworkMenu_ListView>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
|
||||
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
|
||||
{
|
||||
public class FrameworkMenuListVM2 : BasePagedListVM<FrameworkMenu_ListView, BaseSearcher>
|
||||
{
|
||||
public FrameworkMenuListVM2()
|
||||
{
|
||||
this.NeedPage = false;
|
||||
}
|
||||
|
||||
protected override IEnumerable<IGridColumn<FrameworkMenu_ListView>> InitGridHeader()
|
||||
{
|
||||
List<GridColumn<FrameworkMenu_ListView>> rv = new List<GridColumn<FrameworkMenu_ListView>>();
|
||||
rv.AddRange(new GridColumn<FrameworkMenu_ListView>[] {
|
||||
this.MakeGridHeader(x => x.PageName, 300),
|
||||
this.MakeGridHeader(x => x.ModuleName, 150),
|
||||
this.MakeGridHeader(x => x.ShowOnMenu, 60),
|
||||
this.MakeGridHeader(x => x.FolderOnly, 60),
|
||||
this.MakeGridHeader(x => x.IsPublic, 60),
|
||||
this.MakeGridHeader(x => x.DisplayOrder, 60),
|
||||
this.MakeGridHeader(x => x.TenantAllowed, 60),
|
||||
this.MakeGridHeader(x => x.Icon, 100),
|
||||
this.MakeGridHeader(x => x.Children, 100),
|
||||
this.MakeGridHeader(x=>x.ParentId).SetHide(),
|
||||
this.MakeGridHeaderAction(width: 290)
|
||||
});
|
||||
return rv;
|
||||
}
|
||||
|
||||
public override IOrderedQueryable<FrameworkMenu_ListView> GetSearchQuery()
|
||||
{
|
||||
List<FrameworkMenu> data = new List<FrameworkMenu>();
|
||||
using (var maindc = Wtm.CreateDC(false, "default"))
|
||||
{
|
||||
data = maindc.Set<FrameworkMenu>().ToList();
|
||||
}
|
||||
var topdata = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder).Where(x => x.IsInside == false || x.FolderOnly == true || x.Url.EndsWith("/Index") || string.IsNullOrEmpty(x.MethodName)).ToList();
|
||||
foreach (var item in topdata)
|
||||
{
|
||||
if (item.PageName?.StartsWith("MenuKey.") == true)
|
||||
{
|
||||
item.PageName = Localizer[item.PageName];
|
||||
}
|
||||
if (item.ModuleName?.StartsWith("MenuKey.") == true)
|
||||
{
|
||||
item.ModuleName = Localizer[item.ModuleName];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int order = 0;
|
||||
var data2 = topdata.Select(x => new FrameworkMenu_ListView
|
||||
{
|
||||
ID = x.ID,
|
||||
PageName = x.PageName,
|
||||
ModuleName = x.ModuleName,
|
||||
ActionName = x.ActionName,
|
||||
ShowOnMenu = x.ShowOnMenu,
|
||||
FolderOnly = x.FolderOnly,
|
||||
IsPublic = x.IsPublic,
|
||||
DisplayOrder = x.DisplayOrder,
|
||||
ExtraOrder = order++,
|
||||
ParentId = x.ParentId,
|
||||
TenantAllowed = x.TenantAllowed,
|
||||
Icon = x.Icon
|
||||
}).OrderBy(x => x.ExtraOrder).ToList();
|
||||
|
||||
return data2.AsQueryable() as IOrderedQueryable<FrameworkMenu_ListView>;
|
||||
}
|
||||
}
|
||||
public class FrameworkMenu_ListView : TreePoco<FrameworkMenu_ListView>
|
||||
{
|
||||
[Display(Name = "_Admin.PageName")]
|
||||
public string PageName { get; set; }
|
||||
|
||||
[Display(Name = "Codegen.ModuleName")]
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.ActionName")]
|
||||
public string ActionName { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.ShowOnMenu")]
|
||||
public bool? ShowOnMenu { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.FolderOnly")]
|
||||
public bool? FolderOnly { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.IsPublic")]
|
||||
public bool? IsPublic { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.DisplayOrder")]
|
||||
public int? DisplayOrder { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.Icon")]
|
||||
public string Icon { get; set; }
|
||||
|
||||
public bool Allowed { get; set; }
|
||||
|
||||
public bool Denied { get; set; }
|
||||
|
||||
public bool HasChild { get => HasChildren; }
|
||||
|
||||
public string IconClass { get; set; }
|
||||
|
||||
|
||||
public int ExtraOrder { get; set; }
|
||||
|
||||
public bool? IsInside { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.TenantAllowed")]
|
||||
public bool? TenantAllowed { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
|
||||
{
|
||||
public enum FrameworkMenuMode { Normal = 0, RoleMode = 1, RoleSetMode = 2 }
|
||||
public class FrameworkMenuSearcher : BaseSearcher
|
||||
{
|
||||
[Display(Name = "_Admin.PageName")]
|
||||
public string PageName { get; set; }
|
||||
[Display(Name = "Codegen.ModuleName")]
|
||||
public string ModuleName { get; set; }
|
||||
[Display(Name = "_Admin.ActionName")]
|
||||
public string ActionName { get; set; }
|
||||
[Display(Name = "_Admin.ShowOnMenu")]
|
||||
public bool? ShowOnMenu { get; set; }
|
||||
[Display(Name = "_Admin.IsPublic")]
|
||||
public bool? IsPublic { get; set; }
|
||||
[Display(Name = "_Admin.FolderOnly")]
|
||||
public bool? FolderOnly { get; set; }
|
||||
|
||||
public string RoleCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Core.Support.Json;
|
||||
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkRoleVMs;
|
||||
|
||||
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
|
||||
{
|
||||
public class FrameworkMenuVM : BaseCRUDVM<FrameworkMenu>
|
||||
{
|
||||
[Display(Name = "_Admin.IconFont")]
|
||||
public string IconFont { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.Icon")]
|
||||
public string IconFontItem { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<ComboSelectListItem> AllParents { get; set; }
|
||||
[JsonIgnore]
|
||||
public List<ComboSelectListItem> AllModules { get; set; }
|
||||
[JsonIgnore]
|
||||
public List<ComboSelectListItem> AllActions { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.Action")]
|
||||
public List<string> SelectedActionIDs { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.Module")]
|
||||
public string SelectedModule { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.AllowedRole")]
|
||||
public List<string> SelectedRolesIds { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public FrameworkRoleListVM RoleListVM { get; set; }
|
||||
|
||||
public List<ComboSelectListItem> IconSelectItems { get; set; }
|
||||
|
||||
public FrameworkMenuVM()
|
||||
{
|
||||
RoleListVM = new FrameworkRoleListVM();
|
||||
AllActions = new List<ComboSelectListItem>();
|
||||
AllModules = new List<ComboSelectListItem>();
|
||||
|
||||
SelectedRolesIds = new List<string>();
|
||||
}
|
||||
|
||||
protected override void InitVM()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Entity.Icon))
|
||||
{
|
||||
var res = Entity.Icon.Split(' ');
|
||||
IconFont = res[0];
|
||||
IconFontItem = res[1];
|
||||
}
|
||||
|
||||
SelectedRolesIds.AddRange(DC.Set<FunctionPrivilege>().Where(x => x.MenuItemId == Entity.ID && x.RoleCode != null && x.Allowed == true).Select(x => x.RoleCode).ToList());
|
||||
SelectedRolesIds = SelectedRolesIds.Distinct().ToList();
|
||||
var data = DC.Set<FrameworkMenu>().AsNoTracking().ToList();
|
||||
var topMenu = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder);
|
||||
var pids = Entity.GetAllChildrenIDs(DC);
|
||||
AllParents = data.Where(x => x.ID != Entity.ID && !pids.Contains(x.ID) && x.FolderOnly == true).ToList().ToListItems(y => y.PageName, x => x.ID);
|
||||
|
||||
foreach (var p in AllParents)
|
||||
{
|
||||
if (p.Text.StartsWith("MenuKey."))
|
||||
{
|
||||
p.Text = Localizer[p.Text];
|
||||
}
|
||||
}
|
||||
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
var m = Utils.ResetModule(modules);
|
||||
var ms = m.Select(x => new {
|
||||
x.Area,
|
||||
x.IsApi,
|
||||
x.NameSpace,
|
||||
x.ModuleName,
|
||||
x.FullName,
|
||||
IsFront = x.NameSpace.Contains("._Front.") || x.ClassName.EndsWith("_Uni")
|
||||
}).GroupBy(x => new { x.Area?.AreaName, x.IsApi, x.IsFront }).SelectMany(x => x).OrderBy(x=>x.IsApi).ToList();
|
||||
string area = "";
|
||||
bool? isapi = null;
|
||||
bool? isfront = null;
|
||||
for (int i = 0; i < ms.Count; i++)
|
||||
{
|
||||
if (area != ms[i].Area?.AreaName || isapi != ms[i].IsApi || isfront != ms[i].IsFront)
|
||||
{
|
||||
area = ms[i].Area?.AreaName;
|
||||
isapi = ms[i].IsApi;
|
||||
isfront = ms[i].IsFront;
|
||||
var mm = "-----" + (ms[i].Area?.AreaName ?? "Default") + (ms[i].IsFront ? "UniApp" : "") + (ms[i].IsApi == true ? "(api)" : "") + "-----";
|
||||
ms.Insert(i, new
|
||||
{
|
||||
Area = new SimpleArea(),
|
||||
IsApi = false,
|
||||
NameSpace = "",
|
||||
ModuleName = mm,
|
||||
FullName = "",
|
||||
IsFront = false
|
||||
});
|
||||
i++;
|
||||
}
|
||||
}
|
||||
AllModules = ms.ToListItems(y => y.ModuleName, y => y.FullName);
|
||||
foreach (var item in AllModules)
|
||||
{
|
||||
if (item.Value.ToString() == ",")
|
||||
{
|
||||
item.Disabled = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(SelectedModule) == false || (string.IsNullOrEmpty(Entity.Url) == false && Entity.IsInside == true))
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedModule))
|
||||
{
|
||||
SelectedModule = m.Where(x => (x.FullName == Entity.ClassName)).FirstOrDefault()?.FullName;
|
||||
}
|
||||
var mm = m.Where(x => x.FullName == SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName != "Index" && x.IgnorePrivillege == false).ToList();
|
||||
AllActions = mm.ToListItems(y => y.ActionName, y => y.Url);
|
||||
if (SelectedActionIDs == null)
|
||||
{
|
||||
SelectedActionIDs = DC.Set<FrameworkMenu>().Where(x => AllActions.Select(y => y.Value).Contains(x.Url) && x.IsInside == true && x.FolderOnly == false).Select(x => x.Url).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void Validate()
|
||||
{
|
||||
if (Entity.IsInside == true && Entity.FolderOnly == false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedModule) == true)
|
||||
{
|
||||
MSD.AddModelError("SelectedModule", Localizer["Validate.{0}required", Localizer["_Admin.Module"]]);
|
||||
}
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
var test = DC.Set<FrameworkMenu>().Where(x => x.ClassName == this.SelectedModule && (string.IsNullOrEmpty(x.MethodName) || x.MethodName == "Index") && x.ID != Entity.ID).FirstOrDefault();
|
||||
if (test != null)
|
||||
{
|
||||
MSD.AddModelError(" error", Localizer["_Admin.ModuleHasSet"]);
|
||||
}
|
||||
|
||||
}
|
||||
base.Validate();
|
||||
}
|
||||
|
||||
public override void DoEdit(bool updateAllFields = false)
|
||||
{
|
||||
Entity.Icon = $"{IconFont} {IconFontItem}";
|
||||
FC.Add("Entity.Icon", " ");
|
||||
if (Entity.IsInside == false)
|
||||
{
|
||||
if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
|
||||
{
|
||||
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
|
||||
{
|
||||
Entity.Url = "http://" + Entity.Url;
|
||||
}
|
||||
}
|
||||
if(Entity.Url != null)
|
||||
{
|
||||
Entity.Url = Entity.Url.TrimEnd('/');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
|
||||
{
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
var m = Utils.ResetModule(modules, false);
|
||||
var actionPage = m.Where(x => x.FullName == this.SelectedModule)
|
||||
.SelectMany(x => x.Actions).Where(x => x.MethodName == "Index" || x.ActionDes?.IsPage == true)
|
||||
.FirstOrDefault();
|
||||
if (actionPage == null && Entity.ShowOnMenu == true)
|
||||
{
|
||||
MSD.AddModelError("Entity.ModuleId", Localizer["_Admin.NoIndexInModule"]);
|
||||
return;
|
||||
}
|
||||
List<SimpleAction> otherActions = null;
|
||||
|
||||
var mainModule = m.Where(x => x.FullName == this.SelectedModule).FirstOrDefault();
|
||||
if (actionPage == null)
|
||||
{
|
||||
actionPage = new SimpleAction
|
||||
{
|
||||
Module = mainModule,
|
||||
Url = "/" + mainModule.ClassName,
|
||||
ActionName = mainModule.ModuleName
|
||||
};
|
||||
}
|
||||
var mainAction = actionPage;
|
||||
|
||||
Entity.Url = mainAction.Url;
|
||||
Entity.ModuleName = mainModule.ModuleName;
|
||||
Entity.ActionName = mainAction.ActionDes?.Description ?? mainAction.ActionName;
|
||||
Entity.ClassName = mainModule.FullName;
|
||||
Entity.MethodName = null;
|
||||
|
||||
otherActions = m.Where(x => x.FullName == this.SelectedModule)
|
||||
.SelectMany(x => x.Actions)
|
||||
.Where(x => x.MethodName != mainAction.MethodName)
|
||||
.ToList();
|
||||
var actionsInDB = DC.Set<FrameworkMenu>().AsNoTracking().Where(x => x.ParentId == Entity.ID).ToList();
|
||||
int order = 1;
|
||||
Entity.Children = new List<FrameworkMenu>();
|
||||
foreach (var action in otherActions)
|
||||
{
|
||||
if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.Url))
|
||||
{
|
||||
Guid aid = action.ID;
|
||||
var adb = actionsInDB.Where(x => x.Url.ToLower() == action.Url.ToLower()).FirstOrDefault();
|
||||
if (adb != null)
|
||||
{
|
||||
aid = adb.ID;
|
||||
}
|
||||
var menu = new FrameworkMenu();
|
||||
menu.FolderOnly = false;
|
||||
menu.IsPublic = Entity.IsPublic;
|
||||
menu.Parent = Entity;
|
||||
menu.ShowOnMenu = false;
|
||||
menu.DisplayOrder = order++;
|
||||
menu.IsInside = true;
|
||||
menu.Domain = Entity.Domain;
|
||||
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.ModuleName = mainModule.ModuleName;
|
||||
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.ClassName = mainModule.FullName;
|
||||
menu.MethodName = action.MethodName;
|
||||
menu.Url = action.Url;
|
||||
menu.ID = aid;
|
||||
Entity.Children.Add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Entity.Children = new List<FrameworkMenu>();
|
||||
Entity.Url = null;
|
||||
}
|
||||
}
|
||||
if (Entity.FolderOnly == false)
|
||||
{
|
||||
if (FC.ContainsKey("Entity.Children") == false)
|
||||
{
|
||||
FC.Add("Entity.Children", 0);
|
||||
FC.Add("Entity.Children[0].IsPublic", 0);
|
||||
FC.Add("Entity.Children[0].PageName", 0);
|
||||
FC.Add("Entity.Children[0].ModuleName", 0);
|
||||
FC.Add("Entity.Children[0].ActionName", 0);
|
||||
FC.Add("Entity.Children[0].ClassName", 0);
|
||||
FC.Add("Entity.Children[0].MethodName", 0);
|
||||
FC.Add("Entity.Children[0].Url", 0);
|
||||
}
|
||||
}
|
||||
FC.Add("Entity.ModuleName", 0);
|
||||
base.DoEdit();
|
||||
List<Guid> guids = new List<Guid>();
|
||||
guids.Add(Entity.ID);
|
||||
if (Entity.Children != null)
|
||||
{
|
||||
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
|
||||
}
|
||||
AddPrivilege(guids);
|
||||
}
|
||||
|
||||
public override void DoAdd()
|
||||
{
|
||||
Entity.Icon = $"{IconFont} {IconFontItem}";
|
||||
if (Entity.IsInside == false)
|
||||
{
|
||||
if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
|
||||
{
|
||||
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
|
||||
{
|
||||
Entity.Url = "http://" + Entity.Url;
|
||||
}
|
||||
}
|
||||
if(Entity.Url != null)
|
||||
{
|
||||
Entity.Url = Entity.Url.TrimEnd('/');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
|
||||
{
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
|
||||
var m = Utils.ResetModule(modules, false);
|
||||
var actionPage = m.Where(x => x.FullName == this.SelectedModule)
|
||||
.SelectMany(x => x.Actions).Where(x => x.MethodName == "Index" || x.ActionDes?.IsPage == true)
|
||||
.FirstOrDefault();
|
||||
if (actionPage == null && Entity.ShowOnMenu == true)
|
||||
{
|
||||
MSD.AddModelError("Entity.ModuleId", Localizer["_Admin.NoIndexInModule"]);
|
||||
return;
|
||||
}
|
||||
List<SimpleAction> otherActions = null;
|
||||
var mainModule = m.Where(x => x.FullName == this.SelectedModule).FirstOrDefault();
|
||||
if(actionPage == null)
|
||||
{
|
||||
actionPage = new SimpleAction
|
||||
{
|
||||
Module = mainModule,
|
||||
Url = "/" + mainModule.ClassName,
|
||||
ActionName = mainModule.ModuleName
|
||||
};
|
||||
}
|
||||
var mainAction = actionPage;
|
||||
|
||||
Entity.Url = mainAction.Url;
|
||||
Entity.ModuleName = mainModule.ModuleName;
|
||||
Entity.ActionName = mainAction.ActionDes?.Description ?? mainAction.ActionName;
|
||||
Entity.ClassName = mainModule.FullName;
|
||||
Entity.MethodName = null;
|
||||
Entity.Children = new List<FrameworkMenu>();
|
||||
|
||||
otherActions = m.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName != mainAction.MethodName).ToList();
|
||||
int order = 1;
|
||||
foreach (var action in otherActions)
|
||||
{
|
||||
if (SelectedActionIDs?.Contains(action.Url) == true)
|
||||
{
|
||||
FrameworkMenu menu = new FrameworkMenu();
|
||||
menu.FolderOnly = false;
|
||||
menu.IsPublic = Entity.IsPublic;
|
||||
menu.Parent = Entity;
|
||||
menu.ShowOnMenu = false;
|
||||
menu.DisplayOrder = order++;
|
||||
menu.IsInside = true;
|
||||
menu.Domain = Entity.Domain;
|
||||
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.ModuleName = mainModule.ModuleName;
|
||||
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.ClassName = mainModule.FullName;
|
||||
menu.MethodName = action.MethodName;
|
||||
menu.Url = action.Url;
|
||||
Entity.Children.Add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Entity.Children = null;
|
||||
Entity.Url = null;
|
||||
}
|
||||
|
||||
}
|
||||
base.DoAdd();
|
||||
List<Guid> guids = new List<Guid>();
|
||||
guids.Add(Entity.ID);
|
||||
if (Entity.Children != null)
|
||||
{
|
||||
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
|
||||
}
|
||||
AddPrivilege(guids);
|
||||
}
|
||||
|
||||
public void AddPrivilege(List<Guid> menuids)
|
||||
{
|
||||
var admin = DC.Set<FrameworkRole>().Where(x => x.RoleCode == "001").SingleOrDefault();
|
||||
if (admin != null && SelectedRolesIds.Contains(admin.RoleCode) == false)
|
||||
{
|
||||
SelectedRolesIds.Add(admin.RoleCode);
|
||||
}
|
||||
var toremove = DC.Set<FunctionPrivilege>().Where(x => SelectedRolesIds.Contains(x.RoleCode) && menuids.Contains(x.MenuItemId)).ToList();
|
||||
toremove.ForEach(x => DC.DeleteEntity(x));
|
||||
|
||||
foreach (var menuid in menuids)
|
||||
{
|
||||
|
||||
if (SelectedRolesIds != null)
|
||||
{
|
||||
foreach (var code in SelectedRolesIds)
|
||||
{
|
||||
FunctionPrivilege fp = new FunctionPrivilege();
|
||||
fp.MenuItemId = menuid;
|
||||
fp.RoleCode = code;
|
||||
fp.Allowed = true;
|
||||
fp.TenantCode = LoginUserInfo?.CurrentTenant;
|
||||
DC.Set<FunctionPrivilege>().Add(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
DC.SaveChanges();
|
||||
Wtm.RemoveUserCacheByRole(SelectedRolesIds.ToArray()).Wait();
|
||||
}
|
||||
|
||||
|
||||
public override void DoDelete()
|
||||
{
|
||||
try
|
||||
{
|
||||
DC.CascadeDelete(Entity);
|
||||
DC.SaveChanges();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
// WTM默认页面 Wtm buidin page
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
|
||||
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
|
||||
{
|
||||
public class FrameworkMenuVM2 : BaseCRUDVM<FrameworkMenu>
|
||||
{
|
||||
|
||||
[Display(Name = "_Admin.Action")]
|
||||
public List<string> SelectedActionIDs { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.Module")]
|
||||
public string SelectedModule { get; set; }
|
||||
|
||||
[Display(Name = "_Admin.AllowedRole")]
|
||||
public List<string> SelectedRolesCodes { get; set; }
|
||||
|
||||
|
||||
public FrameworkMenuVM2()
|
||||
{
|
||||
SelectedRolesCodes = new List<string>();
|
||||
}
|
||||
|
||||
protected override void InitVM()
|
||||
{
|
||||
SelectedRolesCodes.AddRange(DC.Set<FunctionPrivilege>().Where(x => x.MenuItemId == Entity.ID && x.RoleCode != null && x.Allowed == true).Select(x => x.RoleCode).ToList());
|
||||
SelectedRolesCodes = SelectedRolesCodes.Distinct().ToList();
|
||||
|
||||
var data = DC.Set<FrameworkMenu>().ToList();
|
||||
var topMenu = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder);
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
|
||||
if (Entity.Url != null && Entity.IsInside == true)
|
||||
{
|
||||
SelectedModule = modules.Where(x => x.IsApi == true && (x.FullName == Entity.ClassName)).FirstOrDefault()?.FullName;
|
||||
if (SelectedModule != null)
|
||||
{
|
||||
var urls = modules.Where(x => x.FullName == SelectedModule && x.IsApi == true).SelectMany(x => x.Actions).Where(x => x.IgnorePrivillege == false).Select(x => x.Url).ToList();
|
||||
SelectedActionIDs = DC.Set<FrameworkMenu>().Where(x => urls.Contains(x.Url) && x.IsInside == true && x.FolderOnly == false).Select(x => x.MethodName).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedModule = Entity.Url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Validate()
|
||||
{
|
||||
if (Entity.IsInside == true && Entity.FolderOnly == false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedModule) == true)
|
||||
{
|
||||
MSD.AddModelError("SelectedModule", Localizer["Validate.{0}required", Localizer["_Admin.Module"]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
var test = DC.Set<FrameworkMenu>().Where(x => x.Url != null && x.Url.ToLower() == this.Entity.Url.ToLower() && x.ID != Entity.ID).FirstOrDefault();
|
||||
if (test != null)
|
||||
{
|
||||
MSD.AddModelError(" error", Localizer["_Admin.ModuleHasSet"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
base.Validate();
|
||||
}
|
||||
|
||||
public override void DoEdit(bool updateAllFields = false)
|
||||
{
|
||||
if (Entity.IsInside == false)
|
||||
{
|
||||
if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
|
||||
{
|
||||
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
|
||||
{
|
||||
Entity.Url = "http://" + Entity.Url;
|
||||
}
|
||||
}
|
||||
if (Entity.Url != null)
|
||||
{
|
||||
Entity.Url = Entity.Url.TrimEnd('/');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
|
||||
{
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
var ndc = DC.ReCreate();
|
||||
var actionsInDB = DC.Set<FrameworkMenu>().AsNoTracking().Where(x => x.ParentId == Entity.ID).ToList();
|
||||
var mo = modules.Where(x => x.FullName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
|
||||
if (mo != null)
|
||||
{
|
||||
Entity.ModuleName = mo.ModuleName;
|
||||
Entity.ClassName = mo.FullName;
|
||||
Entity.MethodName = null;
|
||||
|
||||
var otherActions = mo.Actions;
|
||||
int order = 1;
|
||||
Entity.Children = new List<FrameworkMenu>();
|
||||
foreach (var action in otherActions)
|
||||
{
|
||||
if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
|
||||
{
|
||||
Guid aid = action.ID;
|
||||
var adb = actionsInDB.Where(x => x.Url.ToLower() == action.Url.ToLower()).FirstOrDefault();
|
||||
if (adb != null)
|
||||
{
|
||||
aid = adb.ID;
|
||||
}
|
||||
FrameworkMenu menu = new FrameworkMenu();
|
||||
menu.FolderOnly = false;
|
||||
menu.IsPublic = Entity.IsPublic;
|
||||
menu.Parent = Entity;
|
||||
menu.ShowOnMenu = false;
|
||||
menu.DisplayOrder = order++;
|
||||
menu.IsInside = true;
|
||||
menu.Domain = Entity.Domain;
|
||||
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.ModuleName = action.Module.ModuleName;
|
||||
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.Url = action.Url;
|
||||
menu.ClassName = action.Module.FullName;
|
||||
menu.MethodName = action.MethodName;
|
||||
menu.ID = aid;
|
||||
Entity.Children.Add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity.ModuleName = "";
|
||||
Entity.ClassName = "";
|
||||
Entity.MethodName = "";
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Entity.Children = null;
|
||||
Entity.Url = null;
|
||||
}
|
||||
}
|
||||
if (FC.ContainsKey("Entity.Children") == false)
|
||||
{
|
||||
FC.Add("Entity.Children", 0);
|
||||
FC.Add("Entity.Children[0].IsPublic", 0);
|
||||
FC.Add("Entity.Children[0].PageName", 0);
|
||||
FC.Add("Entity.Children[0].ModuleName", 0);
|
||||
FC.Add("Entity.Children[0].ActionName", 0);
|
||||
FC.Add("Entity.Children[0].ClassName", 0);
|
||||
FC.Add("Entity.Children[0].MethodName", 0);
|
||||
FC.Add("Entity.Children[0].Url", 0);
|
||||
}
|
||||
base.DoEdit(updateAllFields);
|
||||
List<Guid> guids = new List<Guid>();
|
||||
guids.Add(Entity.ID);
|
||||
if (Entity.Children != null)
|
||||
{
|
||||
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
|
||||
}
|
||||
AddPrivilege(guids);
|
||||
}
|
||||
|
||||
public override void DoAdd()
|
||||
{
|
||||
if (Entity.IsInside == false)
|
||||
{
|
||||
if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
|
||||
{
|
||||
if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
|
||||
{
|
||||
Entity.Url = "http://" + Entity.Url;
|
||||
}
|
||||
}
|
||||
if (Entity.Url != null)
|
||||
{
|
||||
Entity.Url = Entity.Url.TrimEnd('/');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
|
||||
{
|
||||
var modules = Wtm.GlobaInfo.AllModule;
|
||||
|
||||
var mo = modules.Where(x => x.FullName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
|
||||
if (mo != null)
|
||||
{
|
||||
Entity.ModuleName = mo.ModuleName;
|
||||
Entity.ClassName = mo.FullName;
|
||||
Entity.MethodName = null;
|
||||
|
||||
var otherActions = mo.Actions;
|
||||
int order = 1;
|
||||
Entity.Children = new List<FrameworkMenu>();
|
||||
foreach (var action in otherActions)
|
||||
{
|
||||
if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
|
||||
{
|
||||
FrameworkMenu menu = new FrameworkMenu();
|
||||
menu.FolderOnly = false;
|
||||
menu.IsPublic = Entity.IsPublic;
|
||||
menu.Parent = Entity;
|
||||
menu.ShowOnMenu = false;
|
||||
menu.DisplayOrder = order++;
|
||||
menu.IsInside = true;
|
||||
menu.Domain = Entity.Domain;
|
||||
menu.PageName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.ModuleName = action.Module.ModuleName;
|
||||
menu.ActionName = action.ActionDes?.Description ?? action.ActionName;
|
||||
menu.Url = action.Url;
|
||||
menu.ClassName = action.Module.FullName;
|
||||
menu.MethodName = action.MethodName;
|
||||
Entity.Children.Add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Entity.Children = null;
|
||||
Entity.Url = null;
|
||||
}
|
||||
|
||||
}
|
||||
base.DoAdd();
|
||||
List<Guid> guids = new List<Guid>();
|
||||
guids.Add(Entity.ID);
|
||||
if (Entity.Children != null)
|
||||
{
|
||||
guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
|
||||
}
|
||||
AddPrivilege(guids);
|
||||
}
|
||||
|
||||
public void AddPrivilege(List<Guid> menuids)
|
||||
{
|
||||
var admin = DC.Set<FrameworkRole>().Where(x => x.RoleCode == "001").SingleOrDefault();
|
||||
if (admin != null && SelectedRolesCodes.Contains(admin.RoleCode) == false)
|
||||
{
|
||||
SelectedRolesCodes.Add(admin.RoleCode);
|
||||
}
|
||||
var toremove = DC.Set<FunctionPrivilege>().Where(x => SelectedRolesCodes.Contains(x.RoleCode) && menuids.Contains(x.MenuItemId)).ToList();
|
||||
toremove.ForEach(x => DC.DeleteEntity(x));
|
||||
foreach (var menuid in menuids)
|
||||
{
|
||||
|
||||
if (SelectedRolesCodes != null)
|
||||
{
|
||||
foreach (var code in SelectedRolesCodes)
|
||||
{
|
||||
FunctionPrivilege fp = new FunctionPrivilege();
|
||||
fp.MenuItemId = menuid;
|
||||
fp.RoleCode = code;
|
||||
fp.Allowed = true;
|
||||
DC.Set<FunctionPrivilege>().Add(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
DC.SaveChanges();
|
||||
Wtm.RemoveUserCacheByRole(SelectedRolesCodes.ToArray()).Wait();
|
||||
}
|
||||
|
||||
|
||||
public override void DoDelete()
|
||||
{
|
||||
try
|
||||
{
|
||||
DC.CascadeDelete(Entity);
|
||||
DC.SaveChanges();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user