#443 AddPageAsync

This commit is contained in:
Hamid Reza Mohammadi 2024-06-17 17:14:34 +03:30
parent 62ed5c32b6
commit 04143e9fa2
3 changed files with 74 additions and 12 deletions

View File

@ -16481,6 +16481,13 @@
update digital sources stats
</summary>
</member>
<member name="M:RMuseum.Services.IGanjoorService.AddPageAsync(RMuseum.Models.Ganjoor.GanjoorPage)">
<summary>
add page
</summary>
<param name="page"></param>
<returns></returns>
</member>
<member name="T:RMuseum.Services.IGanjoorTranslationService">
<summary>
translation service implementation
@ -18102,6 +18109,18 @@
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.TagCategoryWithSource(System.Int32,System.String)">
<summary>
tag with sources
</summary>
<param name="catId"></param>
<param name="sourceUrlSlug"></param>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.UpdateDigitalSourcesStats">
<summary>
update digital sources stats
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartFindingCategoryPoemsDuplicates(System.Int32,System.Int32,System.Boolean)">
<summary>
Finding Category Poems Duplicates
@ -18820,18 +18839,6 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.TagCategoryWithSource(System.Int32,System.String)">
<summary>
tag with sources
</summary>
<param name="catId"></param>
<param name="sourceUrlSlug"></param>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.UpdateDigitalSourcesStats">
<summary>
update digital sources stats
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartBatchGenerateGDBFiles">
<summary>
start generating gdb files
@ -19450,6 +19457,13 @@
<param name="catId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.AddPageAsync(RMuseum.Models.Ganjoor.GanjoorPage)">
<summary>
add page
</summary>
<param name="page"></param>
<returns></returns>
</member>
<member name="P:RMuseum.Services.Implementation.GanjoorService.AggressiveCacheEnabled">
<summary>
aggressive cache

View File

@ -1424,5 +1424,12 @@ namespace RMuseum.Services
/// update digital sources stats
/// </summary>
void UpdateDigitalSourcesStats();
/// <summary>
/// add page
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
Task<RServiceResult<GanjoorPage>> AddPageAsync(GanjoorPage page);
}
}

View File

@ -3813,6 +3813,47 @@ namespace RMuseum.Services.Implementation
}
/// <summary>
/// add page
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPage>> AddPageAsync(GanjoorPage page)
{
try
{
if (page.UrlSlug.Contains("/"))
return new RServiceResult<GanjoorPage>(null, "slug could not contain /");
page.UrlSlug = page.UrlSlug.Trim();
page.Title = page.Title.Trim();
if (string.IsNullOrEmpty(page.UrlSlug))
return new RServiceResult<GanjoorPage>(null, "empty url");
if (string.IsNullOrEmpty(page.Title))
return new RServiceResult<GanjoorPage>(null, "empty title");
var newPageId = 1 + await _context.GanjoorPages.MaxAsync(p => p.Id);
while (await _context.GanjoorPoems.Where(p => p.Id == newPageId).AnyAsync())
newPageId++;
page.Id = newPageId;
if(page.ParentId != null)
{
var parentPage = await _context.GanjoorPages.AsNoTracking().Where(p => p.Id == page.ParentId).SingleAsync();
page.FullUrl = parentPage.FullUrl + "/" + page.UrlSlug;
page.FullTitle = parentPage.FullTitle + " » " + page.Title;
}
if (true == await _context.GanjoorPages.Where(p => p.FullUrl == page.FullUrl).AnyAsync())
return new RServiceResult<GanjoorPage>(null, "duplicated full url.");
if (true == await _context.GanjoorPages.Where(p => p.FullTitle == page.FullTitle).AnyAsync())
return new RServiceResult<GanjoorPage>(null, "duplicated full title");
_context.Add(page);
await _context.SaveChangesAsync();
return new RServiceResult<GanjoorPage>(page);
}
catch (Exception exp)
{
return new RServiceResult<GanjoorPage>(null, exp.ToString());
}
}
/// <summary>
/// aggressive cache
/// </summary>