李昊 4 年之前
父節點
當前提交
62b461fe5d

+ 1 - 1
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminArticleGroupController.cs

@@ -42,7 +42,7 @@ namespace GxPress.Api.AdminControllers
         /// <returns></returns>
         [HttpGet("{id}")]
         [AllowAnonymous]
-        public async Task<ArticleGroupResult> Add(int id)
+        public async Task<ArticleGroupResult> GetAsync(int id)
         {
             return await _processGroupRepository.GetAsync(id);
         }

+ 2 - 0
gx_api/GxPress/Model/GxPress.Mappings/ArticleGroupUserMapping.cs

@@ -4,6 +4,7 @@ using System.Text;
 using AutoMapper;
 using GxPress.Entity;
 using GxPress.Result.Admin;
+using GxPress.Result.Article;
 using GxPress.Result.ArticleGroupUser;
 
 namespace GxPress.Mappings
@@ -13,6 +14,7 @@ namespace GxPress.Mappings
         public ArticleGroupUserMapping()
         {
             CreateMap<ArticleGroupUser, ArticleGroupUserListResult>();
+             CreateMap<ArticleGroup, ArticleGroupResult>();
         }
 
     }

+ 12 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/ArticleGroupRepository.cs

@@ -12,6 +12,7 @@ using Dapper;
 using GxPress.Result.Article;
 using System;
 using GxPress.EnumConst;
+using AutoMapper;
 
 namespace GxPress.Repository.Implement
 {
@@ -20,13 +21,15 @@ namespace GxPress.Repository.Implement
         private readonly Repository<ArticleGroup> _repository;
         private readonly string _connectionString;
         private readonly string _databaseTypeStr;
-        public ArticleGroupRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor)
+        private readonly IMapper _mapper;
+        public ArticleGroupRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper _mapper)
         {
             _databaseTypeStr = dbOptionsAccessor.CurrentValue.DatabaseType;
             _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
             var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
             var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
             _repository = new Repository<ArticleGroup>(database);
+            this._mapper = _mapper;
         }
 
         public IDatabase Database => _repository.Database;
@@ -49,7 +52,14 @@ namespace GxPress.Repository.Implement
 
         public async Task<ArticleGroupResult> GetAsync(int id)
         {
-            var result = await _repository.GetAsync<ArticleGroupResult>(Q.Where(nameof(Entity.ArticleGroup.Id), id));
+            var result = new ArticleGroupResult();
+            if (id > 0)
+            {
+                var articleGroup = await _repository.GetAsync(id);
+                result = _mapper.Map<ArticleGroupResult>(articleGroup);
+            }
+            if (result == null)
+                result = new ArticleGroupResult();
             result.StyleCssDictionary = new Dictionary<string, string>();
             Type t = typeof(AppPageStyleCssConst);
             Array arrays = Enum.GetValues(t);