李昊 il y a 4 ans
Parent
commit
0d930d86b6

+ 2 - 1
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminSystemRoleController.cs

@@ -1,5 +1,6 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using GxPress.Request.Menu;
 using GxPress.Request.Role;
 using GxPress.Service.Interface.Role;
 using Microsoft.AspNetCore.Authorization;
@@ -66,7 +67,7 @@ namespace GxPress.Api.AdminControllers
         /// <param name="model"></param>
         /// <returns></returns>
          [HttpPost("add-menu")]
-        public async Task<bool> InsertMenusAsync([FromBody] List<Entity.Menus.Menus> model)
+        public async Task<bool> InsertMenusAsync([FromBody] List<MenuInRequest> model)
         {
             return await roleService.InsertMenusAsync(model);
         }

+ 1 - 1
gx_api/GxPress/Model/GxPress.Entity/Menus/Menus.cs

@@ -64,7 +64,7 @@ namespace GxPress.Entity.Menus
         /// 标题
         /// </summary>
         /// <value></value>
-        [DataColumn]
+       
         public string Title { get; set; }
         /// <summary>
         /// 名称

+ 5 - 3
gx_api/GxPress/Model/GxPress.Mappings/MenuMapping.cs

@@ -1,15 +1,17 @@
 using AutoMapper;
 using GxPress.Entity.Menus;
+using GxPress.Request.Menu;
 
 namespace GxPress.Mappings
 {
-    public class MenuMapping: Profile
+    public class MenuMapping : Profile
     {
         public MenuMapping()
         {
             CreateMap<Menus, Children>();
-             CreateMap<Children, Menus>();
+            CreateMap<Children, Menus>();
+            CreateMap<MenuInRequest, Menus>();
+            CreateMap<Menus, MenuInRequest>();
         }
-        
     }
 }

+ 43 - 0
gx_api/GxPress/Model/GxPress.Request/Menu/MenuInRequest.cs

@@ -0,0 +1,43 @@
+using System.Collections.Generic;
+
+namespace GxPress.Request.Menu
+{
+    /// <summary>
+    /// 
+    /// </summary>
+    public class MenuInRequest
+    {
+        /// <summary>
+        /// 父级ID
+        /// </summary>
+        /// <value></value>
+        public int ParentId { get; set; }
+        /// <summary>
+        /// 标题
+        /// </summary>
+        /// <value></value>
+        public string Title { get; set; }
+        /// <summary>
+        /// 名称
+        /// </summary>
+        /// <value></value>
+        public string Name { get; set; }
+        /// <summary>
+        /// 图标名称
+        /// </summary>
+        /// <value></value>
+        public string Icon { get; set; }
+        /// <summary>
+        /// 孩子
+        /// </summary>
+        /// <value></value>
+        public List<MenuInRequest> Children { get; set; }
+        /// <summary>
+        /// 路径
+        /// </summary>
+        /// <value></value>
+
+        public string Path { get; set; }
+    
+    }
+}

+ 23 - 6
gx_api/GxPress/Service/GxPress.Service.Implement/Role/RoleService.cs

@@ -8,6 +8,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Transactions;
 using AutoMapper;
+using GxPress.Request.Menu;
 
 namespace GxPress.Service.Implement.Role
 {
@@ -18,13 +19,13 @@ namespace GxPress.Service.Implement.Role
 
         private readonly ISystemRoleRepository systemRoleRepository;
 
-       private readonly IMapper _mapper;
-        public RoleService(ISystemRoleMenusRepository systemRoleMenusRepository, IMenusRepository menusRepository, ISystemRoleRepository systemRoleRepository,IMapper _mapper)
+        private readonly IMapper _mapper;
+        public RoleService(ISystemRoleMenusRepository systemRoleMenusRepository, IMenusRepository menusRepository, ISystemRoleRepository systemRoleRepository, IMapper _mapper)
         {
             this.systemRoleRepository = systemRoleRepository;
             this.systemRoleMenusRepository = systemRoleMenusRepository;
             this.menusRepository = menusRepository;
-            this._mapper=_mapper;
+            this._mapper = _mapper;
         }
         /// <summary>
         /// 添加权限菜单关联
@@ -78,7 +79,7 @@ namespace GxPress.Service.Implement.Role
         /// </summary>
         /// <param name="models"></param>
         /// <returns></returns>
-        public async Task<bool> InsertMenusAsync(List<Entity.Menus.Menus> models)
+        public async Task<bool> InsertMenusAsync(List<MenuInRequest> models)
         {
             try
             {
@@ -86,12 +87,28 @@ namespace GxPress.Service.Implement.Role
                 {
                     foreach (var item in models)
                     {
-                        var id = await menusRepository.InsertAsync(item);
+                        var menuEntity = new Entity.Menus.Menus()
+                        {
+                            Icon = item.Icon,
+                            Name = item.Name,
+                            ParentId = item.ParentId,
+                            Path = item.Path,
+                            Title = item.Title
+                        };
+                        var id = await menusRepository.InsertAsync(menuEntity);
                         if (item.Children == null)
                             continue;
                         foreach (var menu in item.Children)
                         {
-                            await menusRepository.InsertAsync(_mapper.Map<Entity.Menus.Menus>(menu));
+                            menuEntity = new Entity.Menus.Menus()
+                            {
+                                Icon = item.Icon,
+                                Name = item.Name,
+                                ParentId = id,
+                                Path = item.Path,
+                                Title = item.Title
+                            };
+                            await menusRepository.InsertAsync(menuEntity);
                         }
                     }
                     transactionScope.Complete();

+ 2 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Role/IRoleService.cs

@@ -1,5 +1,6 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using GxPress.Request.Menu;
 using GxPress.Request.Role;
 
 namespace GxPress.Service.Interface.Role
@@ -38,7 +39,7 @@ namespace GxPress.Service.Interface.Role
         /// <returns></returns>
         Task<bool> InsertMenusAsync(Entity.Menus.Menus model);
 
-        Task<bool> InsertMenusAsync(List<Entity.Menus.Menus> models);
+        Task<bool> InsertMenusAsync(List<MenuInRequest> models);
         /// <summary>
         /// 修改菜单
         /// </summary>