Bläddra i källkod

修复Bug,优化种子数据插入

Yue 3 år sedan
förälder
incheckning
25b5d92d02

+ 92 - 79
SourceCode/Src/VberAdmin.EntityFrameworkCore/Seed/DefaultFunctionCreator.cs

@@ -25,96 +25,96 @@ public class DefaultFunctionCreator
     public void Create()
     {
         _context.DeleteTable("[dbo].[Sys_Functions]");
-        var rootId = CreateCatalog(null, VzConsts.FunRootName, "后台管理系统", 0, "fa fa-home", auth: false);
+        var root = CreateCatalog(null, VzConsts.FunRootName, "后台管理系统", 0, "fa fa-home", auth: false);
 
-        System(rootId);
+        System(root);
 
         Write();
     }
 
-    private void System(int parentId)
+    private void System(SysFunction parent)
     {
-        var sysId = CreateCatalog(parentId, "SystemMg", "系统信息维护", 100, "fa fa-cogs");
+        var system = CreateCatalog(parent, "SystemMg", "系统信息维护", 100, "fa fa-cogs");
         {
-            var id = CreateMenu(sysId, "TenantMg", "租户信息管理", 0, "Bs/Tenant", s: "host");
-            CreateBtn_Curd(id, "租户", "Tenant");
+            var menu = CreateMenu(system, "TenantMg", "租户信息管理", 0, "Bs/Tenant", s: "host");
+            CreateBtn_Curd(menu, "租户", "Tenant");
         }
 
         {
-            var id = CreateMenu(sysId, "RoleMg", "角色信息管理", 0, "Bs/SysRole", s: "", "fas fa-users");
-            CreateBtn_Curd(id, "角色", "Role");
+            var menu = CreateMenu(system, "RoleMg", "角色信息管理", 0, "Bs/SysRole", s: "", "fas fa-users");
+            CreateBtn_Curd(menu, "角色", "Role");
         }
         {
-            var id = CreateMenu(sysId, "UserMg", "用户信息管理", 2, "Bs/SysUser", s: "", icon: "fas fa-user");
-            CreateBtn_Curd(id, "用户", "User");
-            CreateBtn_Other(id, "ResetPassword", "重置密码", 4, "fas fa-key", "btnResetPwd", "User/ResetPassword");
-            CreateBtn_Other(id, "ResetLock", "解除登陆锁定", 5, "fas fa-unlock", "btnResetLock", "User/ResetLock");
-            CreateBtn_Other(id, "Activate", "激活用户", 6, "fas fa-lock-open", "btnActivate", "User/Activate");
-            CreateBtn_Other(id, "DeActivate", "锁定用户", 7, "fas fa-lock", "btnDeActivate", "User/DeActivate");
+            var menu = CreateMenu(system, "UserMg", "用户信息管理", 2, "Bs/SysUser", s: "", icon: "fas fa-user");
+            CreateBtn_Curd(menu, "用户", "User");
+            CreateBtn_Other(menu, "ResetPassword", "重置密码", 4, "fas fa-key", "btnResetPwd", "User/ResetPassword");
+            CreateBtn_Other(menu, "ResetLock", "解除登陆锁定", 5, "fas fa-unlock", "btnResetLock", "User/ResetLock");
+            CreateBtn_Other(menu, "Activate", "激活用户", 6, "fas fa-lock-open", "btnActivate", "User/Activate");
+            CreateBtn_Other(menu, "DeActivate", "锁定用户", 7, "fas fa-lock", "btnDeActivate", "User/DeActivate");
         }
 
         {
-            var id = CreateMenu(sysId, "StateMg", "字典信息管理", 3, "Bs/State", s: "", icon: "fas fa-book");
-            CreateBtn_Query(id);
-            CreateBtn_Update(id, "字典", 2, "State");
+            var menu = CreateMenu(system, "StateMg", "字典信息管理", 3, "Bs/State", s: "", icon: "fas fa-book");
+            CreateBtn_Query(menu);
+            CreateBtn_Update(menu, "字典", 2, "State");
         }
 
         {
-            var id = CreateMenu(sysId, "SettingMg", "配置信息管理", 4, "Bs/Setting", s: "", icon: "fas fa-cog");
-            CreateBtn_Query(id);
-            CreateBtn_Update(id, "配置", 2, "Setting");
+            var menu = CreateMenu(system, "SettingMg", "配置信息管理", 4, "Bs/Setting", s: "", icon: "fas fa-cog");
+            CreateBtn_Query(menu);
+            CreateBtn_Update(menu, "配置", 2, "Setting");
         }
 
         {
-            var id = CreateMenu(sysId, "HelpMg", "帮助信息管理", 5, "Bs/Help", s: "", icon: "fas fa-question");
-            CreateBtn_Curd(id, "帮助", "Help");
+            var menu = CreateMenu(system, "HelpMg", "帮助信息管理", 5, "Bs/Help", s: "", icon: "fas fa-question");
+            CreateBtn_Curd(menu, "帮助", "Help");
         }
 
         {
-            var id = CreateMenu(sysId, "FunctionMg", "功能菜单管理", 6, "Bs/Function", s: "", icon: "fas fa-server");
-            CreateBtn_Query(id);
-            CreateBtn_Update(id, "菜单", 2, "Function");
-            CreateBtn_Other(id, "MoveUp", "上移菜单", 4, "fas fa-arrow-up", "btnMoveUp", "Function/MoveUp");
-            CreateBtn_Other(id, "MoveDown", "下移菜单", 5, "fas fa-arrow-down", "btnMoveDown", "Function/MoveDown");
-            CreateBtn_Other(id, "Refresh", "刷新菜单", 6, "fas fa-retweet", "_btnRefresh", "Function/Refresh");
+            var menu = CreateMenu(system, "FunctionMg", "功能菜单管理", 6, "Bs/Function", s: "", icon: "fas fa-server");
+            CreateBtn_Query(menu);
+            CreateBtn_Update(menu, "菜单", 2, "Function");
+            CreateBtn_Other(menu, "MoveUp", "上移菜单", 4, "fas fa-arrow-up", "btnMoveUp", "Function/MoveUp");
+            CreateBtn_Other(menu, "MoveDown", "下移菜单", 5, "fas fa-arrow-down", "btnMoveDown", "Function/MoveDown");
+            CreateBtn_Other(menu, "Refresh", "刷新菜单", 6, "fas fa-retweet", "_btnRefresh", "Function/Refresh");
         }
 
         {
-            var id = CreateMenu(sysId, "NotificationMg", "通知消息管理", 7, "Bs/Notification", s: "", icon: "far fa-envelope");
-            CreateBtn_Query(id);
-            CreateBtn_Other(id, "SendNotification", "发送通知", 1, "fas fa-envelope-open-text", "_btnSendNotification", "Notification/SendSysNotification");
+            var menu = CreateMenu(system, "NotificationMg", "通知消息管理", 7, "Bs/Notification", s: "", icon: "far fa-envelope");
+            CreateBtn_Query(menu);
+            CreateBtn_Other(menu, "SendNotification", "发送通知", 1, "fas fa-envelope-open-text", "_btnSendNotification", "Notification/SendSysNotification");
         }
 
         {
             //工作流
             {
-                var id = CreateMenu(sysId, "WorkflowMg", "流程信息管理", 1, "Wf/Index", s: "", icon: "fas fa-project-diagram", isShow: false);
-                CreateBtn_Curd(id, "流程", "Workflow");
+                var menu = CreateMenu(system, "WorkflowMg", "流程信息管理", 1, "Wf/Index", s: "", icon: "fas fa-project-diagram", isShow: false);
+                CreateBtn_Curd(menu, "流程", "Workflow");
             }
             {
-                var id = CreateMenu(parentId, "MyWorkflowAuditMg", "流程审批信息", 3, "Wf/Audit", s: "", icon: "fas fa-spell-check", isShow: false);
-                CreateBtn_Query(id);
+                var menu = CreateMenu(parent, "MyWorkflowAuditMg", "流程审批信息", 3, "Wf/Audit", s: "", icon: "fas fa-spell-check", isShow: false);
+                CreateBtn_Query(menu);
             }
             {
-                var id = CreateMenu(parentId, "MyWorkflowApplyMg", "我的流程申请", 1, "Wf/Apply", s: "", icon: "fas fa-user-tie", isShow: false);
-                CreateBtn_Query(id);
+                var menu = CreateMenu(parent, "MyWorkflowApplyMg", "我的流程申请", 1, "Wf/Apply", s: "", icon: "fas fa-user-tie", isShow: false);
+                CreateBtn_Query(menu);
             }
         }
 
         {
-            var id = CreateMenu(sysId, "LogMg", "操作日志管理", 9, "Bs/Log", s: "", icon: "fas fa-list-alt");
-            CreateBtn_Query(id);
+            var menu = CreateMenu(system, "LogMg", "操作日志管理", 9, "Bs/Log", s: "", icon: "fas fa-list-alt");
+            CreateBtn_Query(menu);
         }
         {
-            CreateMenu(parentId, "UserHelpInfo", "用户帮助信息", 101, "Bs/UserHelp", s: "", icon: "fas fa-question-circle");
+            CreateMenu(parent, "UserHelpInfo", "用户帮助信息", 101, "Bs/UserHelp", s: "", icon: "fas fa-question-circle");
         }
         {
-            var id = CreateMenu(sysId, "UserSysSetting", "用户配置", 102, "", icon: "fas fa-cogs", isShow: false);
+            var menu = CreateMenu(system, "UserSysSetting", "用户配置", 102, "", icon: "fas fa-cogs", isShow: false);
             //CreateBtn_Other("LoginImage", "UserSysSetting", "配置登陆页背景", 1, "fas fa-cog", "_Admin_btnLoginImage", "Setting/LoginImage", false);
             //CreateBtn_Other("HomeImage", "UserSysSetting", "配置主页背景", 2, "fas fa-cog", "_Admin_btnHomeImage", "Setting/HomeImage", false);
 
-            CreateBtn_Other(id, "RefreshCache", "刷新缓存", 3, "fas fa-recycle", "_Admin_btnCache", "Setting/CacheRefresh", auth: false);
-            CreateBtn_Other(id, "RefreshLang", "刷新语言包", 4, "fas fa-globe", "_Admin_btnLang", "Setting/LangRefresh", auth: false);
+            CreateBtn_Other(menu, "RefreshCache", "刷新缓存", 3, "fas fa-recycle", "_Admin_btnCache", "Setting/CacheRefresh", auth: false);
+            CreateBtn_Other(menu, "RefreshLang", "刷新语言包", 4, "fas fa-globe", "_Admin_btnLang", "Setting/LangRefresh", auth: false);
         }
 
         {
@@ -126,25 +126,25 @@ public class DefaultFunctionCreator
     /// <summary>
     /// 创建目录
     /// </summary>
-    private int CreateCatalog(int? parentId, string name, string displayName, int sort,
+    private SysFunction CreateCatalog(SysFunction parent, string name, string displayName, int sort,
         string icon = "far fa-list-alt", string s = "", string? c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant, bool isShow = true)
     {
         return isShow
-            ? CreateFunctions(parentId, name, displayName, VzDefinition.FunctionType.Catalog, icon, sort, "", c, s,
+            ? CreateFunctions(parent, name, displayName, VzDefinition.FunctionType.Catalog, icon, sort, "", c, s,
                 auth, multiTenancySides)
-            : Create_NotShow(parentId, name, displayName, sort, icon, "", c, s, auth, multiTenancySides);
+            : Create_NotShow(parent, name, displayName, sort, icon, "", c, s, auth, multiTenancySides);
     }
 
     /// <summary>
     /// 创建菜单
     /// </summary>
-    private int CreateMenu(int? parentId, string name, string displayName, int sort, string url, string s = "",
+    private SysFunction CreateMenu(SysFunction parent, string name, string displayName, int sort, string url, string s = "",
         string icon = "far fa-dot-circle", string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant, bool isShow = true)
     {
         return isShow
-            ? CreateFunctions(parentId, name, displayName, VzDefinition.FunctionType.Menu, icon, sort, url, s, c,
+            ? CreateFunctions(parent, name, displayName, VzDefinition.FunctionType.Menu, icon, sort, url, s, c,
                 auth, multiTenancySides)
-            : Create_NotShow(parentId, name, displayName, sort, icon, "", s, c, auth, multiTenancySides);
+            : Create_NotShow(parent, name, displayName, sort, icon, "", s, c, auth, multiTenancySides);
     }
 
     #region BTN
@@ -153,70 +153,70 @@ public class DefaultFunctionCreator
     ///创建增删改查按钮
     /// </summary>
 
-    private void CreateBtn_Curd(int? parentId, string displayName, string? url = null, bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
+    private void CreateBtn_Curd(SysFunction parent, string displayName, string? url = null, bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        CreateBtn_Query(parentId, 0, auth, multiTenancySides);
-        CreateBtn_Create(parentId, displayName, 1, url, "", auth, multiTenancySides);
-        CreateBtn_Update(parentId, displayName, 2, url, "", auth, multiTenancySides);
-        CreateBtn_Delete(parentId, displayName, 3, url, "", auth, multiTenancySides);
+        CreateBtn_Query(parent, 0, auth, multiTenancySides);
+        CreateBtn_Create(parent, displayName, 1, url, "", auth, multiTenancySides);
+        CreateBtn_Update(parent, displayName, 2, url, "", auth, multiTenancySides);
+        CreateBtn_Delete(parent, displayName, 3, url, "", auth, multiTenancySides);
     }
 
     /// <summary>
     ///创建不是增删改查的按钮
     /// </summary>
-    private void CreateBtn_Other(int? parentId, string name, string displayName, int sort, string icon = "far fa-plus-square", string? s = null, string url = "", string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant, bool isShow = true)
+    private void CreateBtn_Other(SysFunction parent, string name, string displayName, int sort, string icon = "far fa-plus-square", string? s = null, string url = "", string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant, bool isShow = true)
     {
-        s ??= $"btn{parentId}";
+        s ??= $"btn{parent}";
 
         if (isShow)
         {
-            CreateBtn(parentId, name, displayName, sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url}", icon, s, "", auth, multiTenancySides);
+            CreateBtn(parent, name, displayName, sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url}", icon, s, "", auth, multiTenancySides);
         }
         else
         {
-            Create_NotShow(parentId, name, displayName, sort, icon, $"{VzConsts.ApiAppUrl.Ew("/")}{url}", s, c, auth, multiTenancySides);
+            Create_NotShow(parent, name, displayName, sort, icon, $"{VzConsts.ApiAppUrl.Ew("/")}{url}", s, c, auth, multiTenancySides);
         }
     }
 
     /// <summary>
     /// 创建查询按钮
     /// </summary>
-    private void CreateBtn_Query(int? parentId, int sort = 0, bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
+    private void CreateBtn_Query(SysFunction parent, int sort = 0, bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        Create_NotShow(parentId, "Query", "查看页面", sort, "far fa-eye", "", "", "", auth, multiTenancySides);
+        Create_NotShow(parent, "Query", "查看页面", sort, "far fa-eye", "", "", "", auth, multiTenancySides);
     }
 
     /// <summary>
     /// 创建修改按钮
     /// </summary>
-    private void CreateBtn_Create(int? parentId, string displayName, int sort = 1, string? url = null, string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
+    private void CreateBtn_Create(SysFunction parent, string displayName, int sort = 1, string? url = null, string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        CreateBtn(parentId, "Create", $"创建{displayName}", sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url.Ew("/")}Create", "far fa-plus-square", "_btnCreate", c, auth, multiTenancySides);
+        CreateBtn(parent, "Create", $"创建{displayName}", sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url.Ew("/")}Create", "far fa-plus-square", "_btnCreate", c, auth, multiTenancySides);
     }
 
     /// <summary>
     /// 创建修改按钮
     /// </summary>
-    private void CreateBtn_Update(int? parentId, string displayName, int sort = 2, string? url = null, string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
+    private void CreateBtn_Update(SysFunction parent, string displayName, int sort = 2, string? url = null, string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        CreateBtn(parentId, "Update", $"修改{displayName}", sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url.Ew("/")}Update", "far fa-edit", "btnUpdate", c, auth, multiTenancySides);
+        CreateBtn(parent, "Update", $"修改{displayName}", sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url.Ew("/")}Update", "far fa-edit", "btnUpdate", c, auth, multiTenancySides);
     }
 
     /// <summary>
     /// 创建删除按钮
     /// </summary>
-    private void CreateBtn_Delete(int? parentId, string displayName, int sort = 3, string? url = null, string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
+    private void CreateBtn_Delete(SysFunction parent, string displayName, int sort = 3, string? url = null, string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        CreateBtn(parentId, "Delete", $"删除{displayName}", sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url.Ew("/")}Delete", "far fa-minus-square", "btnDelete", c, auth, multiTenancySides);
+        CreateBtn(parent, "Delete", $"删除{displayName}", sort, $"{VzConsts.ApiAppUrl.Ew("/")}{url.Ew("/")}Delete", "far fa-minus-square", "btnDelete", c, auth, multiTenancySides);
     }
 
     /// <summary>
     /// 创建按钮
     /// </summary>
-    private void CreateBtn(int? parentId, string name, string displayName, int sort, string? url, string icon,
+    private void CreateBtn(SysFunction parent, string name, string displayName, int sort, string? url, string icon,
         string? s, string c = "btn btn-default", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        CreateFunctions(parentId, name, displayName, VzDefinition.FunctionType.Button, icon, sort, url, s, c, auth, multiTenancySides);
+        CreateFunctions(parent, name, displayName, VzDefinition.FunctionType.Button, icon, sort, url, s, c, auth, multiTenancySides);
     }
 
     #endregion BTN
@@ -224,17 +224,16 @@ public class DefaultFunctionCreator
     /// <summary>
     /// 创建不显示的
     /// </summary>
-    private int Create_NotShow(int? parentId, string name, string displayName, int sort, string icon, string? url = "", string? s = "", string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
+    private SysFunction Create_NotShow(SysFunction parent, string name, string displayName, int sort, string icon, string? url = "", string? s = "", string c = "", bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        return CreateFunctions(parentId, name, displayName, VzDefinition.FunctionType.NotShow, icon, sort, url, s, c, auth, multiTenancySides);
+        return CreateFunctions(parent, name, displayName, VzDefinition.FunctionType.NotShow, icon, sort, url, s, c, auth, multiTenancySides);
     }
 
     /// <summary>
     /// 创建功能菜单
     /// </summary>
-    private int CreateFunctions(int? parentId, string name, string displayName, VzDefinition.FunctionType funType, string icon, int sort, string? url, string? script, string @class, bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
+    private SysFunction CreateFunctions(SysFunction parent, string name, string displayName, VzDefinition.FunctionType funType, string icon, int sort, string? url, string? script, string @class, bool auth = true, MultiTenancySides multiTenancySides = MultiTenancySides.Tenant)
     {
-        var parent = _context.SysFunctions.FirstOrDefault(a => a.Id == parentId);
         if (parent == null && name != VzConsts.FunRootName)
         {
             throw new Exception("未找到父节点");
@@ -242,13 +241,13 @@ public class DefaultFunctionCreator
 
         var permissionName = parent == null ? "Vber" : $"{parent.PermissionName}.{name}";
 
-        var fun = _context.SysFunctions.FirstOrDefault(e => e.PermissionName == permissionName && e.ParentNo == parentId);
+        var fun = _context.SysFunctions.FirstOrDefault(e => e.PermissionName == permissionName);
         if (fun == null)
         {
             fun = new SysFunction
             {
                 Name = name,
-                ParentNo = parentId,
+                ParentNo = parent?.Id,
                 DisplayName = displayName,
                 PermissionName = permissionName,
                 FunctionType = funType,
@@ -264,10 +263,25 @@ public class DefaultFunctionCreator
             };
             _context.SysFunctions.Add(fun);
             _context.SaveChanges();
-            fun.Path = parent == null ? fun.Id + "" : $"{parent.Path}.{fun.Id}";
-            _context.SysFunctions.Update(fun);
         }
-
+        else
+        {
+            fun.Name = name;
+            fun.ParentNo = parent?.Id;
+            fun.DisplayName = displayName;
+            fun.PermissionName = permissionName;
+            fun.FunctionType = funType;
+            fun.Icon = icon;
+            fun.Sort = sort;
+            fun.Depth = (parent?.Depth ?? 0) + 1;
+            fun.Class = @class;
+            fun.Script = script;
+            fun.Url = url;
+            fun.NeedAuth = auth;
+            fun.MultiTenancySides = multiTenancySides;
+        }
+        fun.Path = parent == null ? fun.Id + "" : $"{parent.Path}.{fun.Id}";
+        _context.SysFunctions.Update(fun);
         var permName = fun.PermissionName.Replace(".", "");
         PermissionStr += $"    public const string {permName} = \"{fun.PermissionName}\";\r\n";
 
@@ -277,8 +291,7 @@ public class DefaultFunctionCreator
             LangStr += $"    <text name=\"{permName}\" value=\"{fun.DisplayName}\" />\r\n";
         }
 
-        if (fun.Id != null) return (int)fun.Id;
-        return 0;
+        return fun;
     }
 
     #endregion CREATE

+ 30 - 13
SourceCode/Src/VberAdmin.EntityFrameworkCore/Seed/DefaultSettingAndStateCreator.cs

@@ -3,6 +3,7 @@ using Abp.MultiTenancy;
 using Abp.Net.Mail;
 
 using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
 
 using VberAdmin.DomainService.Settings;
 using VberAdmin.EntityFrameworkCore;
@@ -63,12 +64,19 @@ public class DefaultSettingAndStateCreator
     private void CreateSetting(string name, string value, int? tenantId = null)
     {
         tenantId ??= _tenantId;
-        if (_context.SysSettings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
+        var entity = _context.SysSettings.IgnoreQueryFilters()
+            .FirstOrDefault(s => s.Name == name && s.TenantId == tenantId && s.UserId == null);
+        if (entity == null)
         {
-            return;
+            _context.SysSettings.Add(new SysSetting(tenantId, null, name, value));
+        }
+        else
+        {
+            entity.Name = name;
+            entity.TenantId = tenantId;
+            entity.Value = value;
+            entity.UserId = null;
         }
-
-        _context.SysSettings.Add(new SysSetting(tenantId, null, name, value));
         _context.SaveChanges();
     }
 
@@ -126,18 +134,27 @@ public class DefaultSettingAndStateCreator
 
     private void CreateState(string name, string c, string v, string d)
     {
-        if (_context.SysStates.Any(s => s.CodeKey == c && s.CodeValue == v))
+        var entity = _context.SysStates.IgnoreQueryFilters().FirstOrDefault(s => s.CodeKey == c && s.CodeValue == v);
+        if (entity == null)
         {
-            return;
+            entity = new SysState()
+            {
+                Name = name,
+                CodeKey = c,
+                CodeValue = v,
+                DisplayValue = d,
+            };
+            _context.SysStates.Add(entity);
         }
-
-        _context.SysStates.Add(new SysState()
+        else
         {
-            Name = name,
-            CodeKey = c,
-            CodeValue = v,
-            DisplayValue = d,
-        });
+            entity.Name = name;
+            entity.CodeKey = c;
+            entity.CodeValue = v;
+            entity.DisplayValue = d;
+            _context.SysStates.Update(entity);
+        }
+
         _context.SaveChanges();
     }
 

+ 1 - 1
SourceCode/Src/VberAdmin.Web.Mvc/wwwroot/js/vber.base.js

@@ -3527,7 +3527,7 @@ $(function () {
                             return v;
                         }),
                         pagination: {
-                            more: (params.page * 10) < data.totalCount
+                            more: (params.page * take()) < data.totalCount
                         }
                     };
                     return result;