李昊 4 years ago
parent
commit
fd67f40b9c

+ 5 - 3
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminMediaController.cs

@@ -1,7 +1,9 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using GxPress.Auth;
+using GxPress.Common.Page;
 using GxPress.Repository.Interface.Media;
+using GxPress.Request.Media;
 using GxPress.Result.Media;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
@@ -67,12 +69,12 @@ namespace GxPress.Api.AdminControllers
         /// <summary>
         /// 查询
         /// </summary>
-        /// <param name="mediaType"></param>
+        /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("list/{mediaType}")]
-        public async Task<IEnumerable<Entity.tede2.Media.Media>> GetAllAsync(int mediaType)
+        public async Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request)
         {
-            return await mediaRepository.GetAllAsync(mediaType);
+            return await mediaRepository.GetAllAsync(request);
         }
     }
 }

+ 10 - 10
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminSystemRoleController.cs

@@ -32,17 +32,17 @@ namespace GxPress.Api.AdminControllers
         }
 
         /// <summary>
-        /// 添加权限
+        /// 添加 角色和权限
         /// </summary>
-        /// <param name="model"></param>
+        /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("add-role")]
-        public async Task<bool> InsertSystemRoleAsync(Entity.SystemRole.SystemRole model)
+        public async Task<bool> InsertSystemRoleAsync(RoleInRequest request)
         {
-            return await roleService.InsertSystemRoleAsync(model);
+            return await roleService.InsertSystemRoleAsync(request);
         }
         /// <summary>
-        /// 获取所有权限
+        /// 获取所有角色
         /// </summary>
         /// <returns></returns>
         [HttpGet("role")]
@@ -51,14 +51,14 @@ namespace GxPress.Api.AdminControllers
             return await roleService.GetSystemRoleAllAsync();
         }
         /// <summary>
-        /// 修改权限
+        /// 修改角色 权限
         /// </summary>
-        /// <param name="model"></param>
+        /// <param name="request"></param>
         /// <returns></returns>
         [HttpPut("update-role")]
-        public async Task<bool> UpdateSystemRoleAsync(Entity.SystemRole.SystemRole model)
+        public async Task<bool> UpdateSystemRoleAsync(RoleInRequest request)
         {
-            return await roleService.UpdateSystemRoleAsync(model);
+            return await roleService.UpdateSystemRoleAsync(request);
         }
         /// <summary>
         /// 删除权限
@@ -106,7 +106,7 @@ namespace GxPress.Api.AdminControllers
         /// <param name="roleId"></param>
         /// <returns></returns>
         [HttpGet("menus/{roid}")]
-        public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync(int roleId)
+        public async Task<List<MenuInRequest>> GetMenusAllAsync(int roleId)
         {
             //获取
             return await roleService.GetMenusAllAsync(roleId);

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

@@ -14,6 +14,6 @@ namespace GxPress.Entity.SystemRole
         /// </summary>
         /// <value></value>
         [DataColumn]
-        public int Name { get; set; }
+        public string Name { get; set; }
     }
 }

+ 12 - 0
gx_api/GxPress/Model/GxPress.Request/Media/MediaRequest.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using GxPress.Common.Page;
 
 namespace GxPress.Request.Media
 {
@@ -165,4 +166,15 @@ namespace GxPress.Request.Media
         /// </summary>
         public string LableName { get; set; }
     }
+    /// <summary>
+    /// 
+    /// </summary>
+    public class MediaSearchRequest : PageParameter
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int MediaType { get; set; }
+    }
 }

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

@@ -8,6 +8,11 @@ namespace GxPress.Request.Menu
     public class MenuInRequest
     {
         /// <summary>
+        /// ID
+        /// </summary>
+        /// <value></value>
+        public int Id{get;set;}
+        /// <summary>
         /// 父级ID
         /// </summary>
         /// <value></value>

+ 19 - 2
gx_api/GxPress/Model/GxPress.Request/Role/RoleRequest.cs

@@ -2,9 +2,26 @@ using System.Collections.Generic;
 
 namespace GxPress.Request.Role
 {
-    public class RoleRequest
+    /// <summary>
+    /// 添加角色和权限
+    /// </summary>
+    public class RoleInRequest
     {
-
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 角色名称
+        /// </summary>
+        /// <value></value>
+        public string Name { get; set; }
+        /// <summary>
+        /// 菜单
+        /// </summary>
+        /// <value></value>
+        public List<SystemRoleMenuInRequest> SystemRoleMenuInRequest { get; set; }
     }
     /// <summary>
     /// 权限关联

+ 11 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -10,6 +10,8 @@ using GxPress.Result.Media;
 using Microsoft.Extensions.Options;
 using System.Transactions;
 using GxPress.Common.Exceptions;
+using GxPress.Common.Page;
+using GxPress.Request.Media;
 
 namespace GxPress.Repository.Implement.Media
 {
@@ -130,9 +132,16 @@ namespace GxPress.Repository.Implement.Media
             return await _repository.UpdateAsync(query) > 0;
         }
 
-        public async Task<IEnumerable<Entity.tede2.Media.Media>> GetAllAsync(int mediaType)
+        public async Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request)
         {
-            return await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.Media.MediaType), mediaType).OrderByDesc(nameof(Entity.tede2.Media.Media.Sort)));
+            var result = new PagedList<Entity.tede2.Media.Media>();
+            var query = Q.NewQuery();
+            query.Where(nameof(Entity.tede2.Media.Media.MediaType), request.MediaType);
+            result.Total = await _repository.CountAsync(query);
+            var item = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage).OrderByDesc(nameof(Entity.tede2.Media.Media.Sort)));
+            result.Items = item;
+
+            return result;
         }
 
         public async Task<bool> UpdateAsync(MediaResult result)

+ 4 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemRole/SystemRoleRepository.cs

@@ -32,6 +32,10 @@ namespace GxPress.Repository.Implement.SystemRole
 
         }
 
+        public async Task<Entity.SystemRole.SystemRole> GetRoleAsync(int id)
+        {
+            return await _repository.GetAsync(id);
+        }
         public async Task<bool> UpdateAsync(Entity.SystemRole.SystemRole model)
         {
             return await _repository.UpdateAsync(model);

+ 4 - 4
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaRepository.cs

@@ -1,7 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
 using Datory;
+using GxPress.Common.Page;
+using GxPress.Request.Media;
 using GxPress.Result.Media;
 
 namespace GxPress.Repository.Interface.Media
@@ -25,6 +25,6 @@ namespace GxPress.Repository.Interface.Media
          Task<bool> UpdateAsync(MediaResult result);
        Task<bool> UpdateAsync(SqlKata.Query query);
 
-        Task<IEnumerable<Entity.tede2.Media.Media>> GetAllAsync(int mediaType);
+        Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request);
     }
 }

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/SystemRole/ISystemRoleRepository.cs

@@ -12,5 +12,6 @@ namespace GxPress.Repository.Interface.SystemRole
 
         Task<bool> DeleteAsync(int id);
         Task<IEnumerable<Entity.SystemRole.SystemRole>> GetSystemRolesAllAsync();
+        Task<Entity.SystemRole.SystemRole> GetRoleAsync(int id);
     }
 }

+ 50 - 7
gx_api/GxPress/Service/GxPress.Service.Implement/Role/RoleService.cs

@@ -9,6 +9,7 @@ using System.Linq;
 using System.Transactions;
 using AutoMapper;
 using GxPress.Request.Menu;
+using System.Transactions;
 
 namespace GxPress.Service.Implement.Role
 {
@@ -42,9 +43,27 @@ namespace GxPress.Service.Implement.Role
         /// </summary>
         /// <param name="models"></param>
         /// <returns></returns>
-        public async Task<bool> InsertSystemRoleAsync(Entity.SystemRole.SystemRole model)
+        public async Task<bool> InsertSystemRoleAsync(RoleInRequest request)
         {
-            return await systemRoleRepository.InsertAsync(model) > 0;
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    var role = new Entity.SystemRole.SystemRole();
+                    role.Name = request.Name;
+                    var roleId = await systemRoleRepository.InsertAsync(role);
+                    var models = new SystemRoleMenusInRequest();
+                    models.RoleId = roleId;
+                    models.SystemRoleMenuInRequest = request.SystemRoleMenuInRequest;
+                    await systemRoleMenusRepository.InsertAsync(models);
+                    transactionScope.Complete();
+                }
+            }
+            catch (System.Exception ex)
+            {
+                throw new Common.Exceptions.BusinessException(ex.Message);
+            }
+            return true;
         }
 
         public async Task<IEnumerable<Entity.SystemRole.SystemRole>> GetSystemRoleAllAsync()
@@ -56,9 +75,27 @@ namespace GxPress.Service.Implement.Role
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
-        public async Task<bool> UpdateSystemRoleAsync(Entity.SystemRole.SystemRole model)
+        public async Task<bool> UpdateSystemRoleAsync(RoleInRequest request)
         {
-            return await systemRoleRepository.UpdateAsync(model);
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    var role = await systemRoleRepository.GetRoleAsync(request.Id);
+                    role.Name = request.Name;
+                    await systemRoleRepository.UpdateAsync(role);
+                    var models = new SystemRoleMenusInRequest();
+                    models.RoleId = request.Id;
+                    models.SystemRoleMenuInRequest = request.SystemRoleMenuInRequest;
+                    await systemRoleMenusRepository.InsertAsync(models);
+                    transactionScope.Complete();
+                }
+            }
+            catch (System.Exception ex)
+            {
+                throw new Common.Exceptions.BusinessException(ex.Message);
+            }
+            return true;
         }
         /// <summary>
         /// 删除权限
@@ -148,12 +185,18 @@ namespace GxPress.Service.Implement.Role
         /// </summary>
         /// <param name="roleId"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync(int roleId)
+        public async Task<List<MenuInRequest>> GetMenusAllAsync(int roleId)
         {
             //获取
             var models = await systemRoleMenusRepository.GetAllAsync(roleId);
-
-            return await menusRepository.GetAllAsync(models.Select(n => n.Id).ToList());
+            var item = await menusRepository.GetAllAsync(models.Select(n => n.Id).ToList());
+            var result = new List<MenuInRequest>();
+            result = item.Where(n => n.ParentId == 0).Select(n => _mapper.Map<MenuInRequest>(n)).ToList();
+            foreach (var request in result)
+            {
+                request.Children=item.Where(n => n.ParentId == request.Id).Select(n => _mapper.Map<MenuInRequest>(n)).ToList();
+            }
+            return result;
         }
 
         /// <summary>

+ 3 - 3
gx_api/GxPress/Service/GxPress.Service.Interface/Role/IRoleService.cs

@@ -19,13 +19,13 @@ namespace GxPress.Service.Interface.Role
         /// </summary>
         /// <param name="models"></param>
         /// <returns></returns>
-        Task<bool> InsertSystemRoleAsync(Entity.SystemRole.SystemRole model);
+        Task<bool> InsertSystemRoleAsync(RoleInRequest request);
         /// <summary>
         /// 修改权限
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
-        Task<bool> UpdateSystemRoleAsync(Entity.SystemRole.SystemRole model);
+        Task<bool> UpdateSystemRoleAsync(RoleInRequest request);
         /// <summary>
         /// 删除权限
         /// </summary>
@@ -57,7 +57,7 @@ namespace GxPress.Service.Interface.Role
         /// </summary>
         /// <param name="roleId"></param>
         /// <returns></returns>
-        Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync(int roleId);
+        Task<List<MenuInRequest>> GetMenusAllAsync(int roleId);
 
         /// <summary>
         /// 获取所有菜单