Skip to content

Commit

Permalink
文章关联词条展示详细信息
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleFish-233 committed Nov 21, 2022
1 parent 9b60645 commit 8d67d1d
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 301 deletions.
Expand Up @@ -611,65 +611,24 @@ public ArticleViewModel GetArticleViewModelAsync(Article article)
//读取词条信息
var relevances = new List<RelevancesViewModel>();

if (article.Entries.Any(s => s.IsHidden == false))
foreach (var item in article.Entries.Where(s => s.IsHidden == false))
{
var temp = new List<RelevancesKeyValueModel>();
relevances.Add(new RelevancesViewModel
{
Modifier = "词条",
Informations = temp
});
foreach (var item in article.Entries.Where(s => s.IsHidden == false))
{
temp.Add(new RelevancesKeyValueModel
{
DisplayName = item.Name ?? item.DisplayName,
DisplayValue = item.BriefIntroduction,
Id = item.Id,
});
}
model.RelatedEntries.Add(_appHelper.GetEntryInforTipViewModel(item));
}
if (article.ArticleRelationFromArticleNavigation.Any(s => s.ToArticleNavigation.IsHidden))
foreach (var item in article.ArticleRelationFromArticleNavigation.Where(s => s.ToArticleNavigation.IsHidden==false).Select(s=>s.ToArticleNavigation))
{
var temp = new List<RelevancesKeyValueModel>();
relevances.Add(new RelevancesViewModel
{
Modifier = "文章",
Informations = temp
});
foreach (var nav in article.ArticleRelationFromArticleNavigation.Where(s => s.ToArticleNavigation.IsHidden == false))
{
var item = nav.ToArticleNavigation;
temp.Add(new RelevancesKeyValueModel
{
DisplayName = item.Name ?? item.DisplayName,
DisplayValue = item.BriefIntroduction,
Id = item.Id,
});
}
model.RelatedArticles.Add(_appHelper.GetArticleInforTipViewModel(item));
}
if (article.Outlinks.Count > 0)
foreach (var item in article.Outlinks)
{
var temp = new List<RelevancesKeyValueModel>();
relevances.Add(new RelevancesViewModel
model.RelatedOutlinks.Add(new RelevancesKeyValueModel
{
Modifier = "外部链接",
Informations = temp
DisplayName = item.Name,
DisplayValue = item.BriefIntroduction,
Link = item.Link,
});
foreach (var item in article.Outlinks)
{

temp.Add(new RelevancesKeyValueModel
{
DisplayName = item.Name,
DisplayValue = item.BriefIntroduction,
Link = item.Link,
});
}
}

model.Relevances = relevances;

return model;
}

Expand Down
Expand Up @@ -72,54 +72,6 @@ public class ArticlesAPIController : ControllerBase
_editRecordService = editRecordService;
}

/// <summary>
/// 通过Id获取文章的真实数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
[AllowAnonymous]
public async Task<ActionResult<Article>> GetArticleDataAsync(long id)
{
//获取当前用户ID
var user = await _appHelper.GetAPICurrentUserAsync(HttpContext);

var article = await _articleRepository.GetAll().AsNoTracking()
.Include(s => s.Entries)
.Include(s => s.Outlinks)
.Include(s => s.ArticleRelationFromArticleNavigation).ThenInclude(s => s.ToArticleNavigation)
.Include(s => s.Examines).AsSplitQuery().FirstOrDefaultAsync(x => x.Id == id);

if (article == null)
{
return NotFound();
}
else
{
//判断当前是否隐藏
if (article.IsHidden == true)
{
if (user == null || await _userManager.IsInRoleAsync(user, "Admin") != true)
{
return NotFound();
}
article.IsHidden = true;
}
else
{
article.IsHidden = false;

}
//需要清除环回引用
foreach (var item in article.Examines)
{
item.Article = null;
}
return article;
}

}

[AllowAnonymous]
[HttpGet("{id}")]
public async Task<ActionResult<ArticleViewModel>> GetArticleViewAsync(long id)
Expand Down Expand Up @@ -591,7 +543,6 @@ public async Task<ActionResult<Result>> EditArticleMainAsync(EditArticleMainView

}


[HttpGet("{id}")]
public async Task<ActionResult<EditArticleMainPageViewModel>> EditArticleMainPageAsync(long Id)
{
Expand Down
Expand Up @@ -68,73 +68,6 @@ public class EntriesAPIController : ControllerBase
_logger = logger;
}

/// <summary>
/// 通过Id获取词条的真实数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
[AllowAnonymous]
public async Task<ActionResult<Entry>> GetEntryDataAsync(int id)
{
//获取当前用户ID
var user = await _appHelper.GetAPICurrentUserAsync(HttpContext);

var entry = await _entryRepository.GetAll().AsNoTracking()
.Include(s => s.Outlinks)
.Include(s => s.EntryRelationFromEntryNavigation)
.Include(s => s.Articles)
.Include(s => s.Examines)
.Include(s => s.Information).ThenInclude(s => s.Additional)
.Include(s => s.Tags)
.Include(s => s.Pictures).AsSplitQuery().FirstOrDefaultAsync(x => x.Id == id && x.IsHidden != true);
if (entry == null)
{
return NotFound();
}
else
{
//判断当前是否隐藏
if (entry.IsHidden == true)
{
if (user == null || await _userManager.IsInRoleAsync(user, "Admin") != true)
{

return NotFound();
}
entry.IsHidden = true;
}
else
{
entry.IsHidden = false;
}

//需要清除环回引用
foreach (var item in entry.Examines)
{
item.Entry = null;
}
//需要清除环回引用
foreach (var item in entry.Tags)
{
item.Entries = null;
}
//需要清除环回引用
foreach (var item in entry.Articles)
{
item.Entries = null;
}
//需要清除环回引用
foreach (var item in entry.EntryRelationFromEntryNavigation)
{
item.FromEntryNavigation = null;
item.ToEntryNavigation = null;
}
return entry;
}

}

/// <summary>
/// 通过Id获取为页面显示优化后的词条信息
/// </summary>
Expand Down
Expand Up @@ -64,9 +64,6 @@ public class TagsAPIController : ControllerBase
_articleService = articleService;
}




[AllowAnonymous]
[HttpGet("{Id}")]
public async Task<ActionResult<TagIndexViewModel>> GetTagAsync(int id)
Expand Down
10 changes: 10 additions & 0 deletions CnGalWebSite/CnGalWebSite.DataModel/Model/Video.cs
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CnGalWebSite.DataModel.Model
{
internal class Video
{
}
}
@@ -1,4 +1,5 @@
using CnGalWebSite.DataModel.Model;
using CnGalWebSite.DataModel.ViewModel.Search;
using CnGalWebSite.DataModel.ViewModel.Space;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -94,7 +95,14 @@ public class ArticleViewModel
/// <summary>
/// 相关性列表
/// </summary>
public List<RelevancesViewModel> Relevances { get; set; } = new List<RelevancesViewModel>();
public List<EntryInforTipViewModel> RelatedEntries { get; set; } = new List<EntryInforTipViewModel>();

public List<ArticleInforTipViewModel> RelatedArticles { get; set; } = new List<ArticleInforTipViewModel>();

/// <summary>
/// 外部链接
/// </summary>
public List<RelevancesKeyValueModel> RelatedOutlinks { get; set; } = new List<RelevancesKeyValueModel> { };

public UserInforViewModel UserInfor { get; set; } = new UserInforViewModel();

Expand Down
5 changes: 3 additions & 2 deletions CnGalWebSite/CnGalWebSite.Helper/CnGalWebSite.Helper.csproj
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand All @@ -9,8 +9,9 @@

<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="6.6.2" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="Masa.Blazor" Version="0.6.0" />

<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="7.0.0" />
<PackageReference Include="NodaTime" Version="3.1.5" />
Expand Down
4 changes: 3 additions & 1 deletion CnGalWebSite/CnGalWebSite.Server/Startup.cs
@@ -1,4 +1,5 @@
using Blazored.LocalStorage;
using Blazored.SessionStorage;
using CnGalWebSite.DataModel.Application.Examines;
using CnGalWebSite.DataModel.Application.Helper;
using CnGalWebSite.DataModel.Helper;
Expand Down Expand Up @@ -58,7 +59,8 @@ public void ConfigureServices(IServiceCollection services)

_ = services.AddScoped(sp => new HttpClient());

_ = services.AddBlazoredLocalStorage();
_ = services.AddBlazoredLocalStorage()
.AddBlazoredSessionStorage();

_ = services.AddAuthorizationCore();
_ = services.AddScoped<AuthenticationStateProvider, ApiAuthenticationStateProvider>();
Expand Down
Expand Up @@ -53,6 +53,7 @@

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="Blazored.SessionStorage" Version="2.2.0" />
<PackageReference Include="Chronos.Blazor.Cropper" Version="1.2.11" />
<PackageReference Include="EPPlus" Version="6.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.0" />
Expand Down

0 comments on commit 8d67d1d

Please sign in to comment.