#224 generate periods method is nearly complete
This commit is contained in:
parent
0912ffd373
commit
66be96efab
@ -17,19 +17,14 @@
|
||||
@foreach (var poet in Model.Poets)
|
||||
{
|
||||
<text>
|
||||
var b = $("#@($"birth-{poet.Id}")").val();
|
||||
var d = $("#@($"death-{poet.Id}")").val();
|
||||
var o = $("#@($"pinorder-{poet.Id}")").val();
|
||||
var url = '?handler=SavePoetMeta';
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
url: '?handler=SavePoetMeta',
|
||||
data: {
|
||||
id: @poet.Id,
|
||||
birth: b,
|
||||
death: d,
|
||||
pinorder: o
|
||||
birth: $("#@($"birth-{poet.Id}")").val(),
|
||||
death: $("#@($"death-{poet.Id}")").val(),
|
||||
pinorder: $("#@($"pinorder-{poet.Id}")").val()
|
||||
},
|
||||
error: function () {
|
||||
alert('برای @poet.Nickname خطا رخ داد.')
|
||||
@ -37,7 +32,17 @@
|
||||
});
|
||||
</text>
|
||||
}
|
||||
alert('انجام شد.');
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '?handler=UpdatePeriods',
|
||||
success: function () {
|
||||
alert('انجام شد.');
|
||||
},
|
||||
error: function () {
|
||||
alert('در مرحلهٔ نهایی خطا رخ داد.')
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@ -94,6 +94,21 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
return new OkObjectResult(false);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostUpdatePeriodsAsync()
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var response = await secureClient.PostAsync($"{APIRoot.Url}/api/ganjoor/periods", null);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return new OkObjectResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
return new OkObjectResult(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// memory cache
|
||||
/// </summary>
|
||||
|
||||
@ -163,6 +163,27 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// regenerate half centuries
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost]
|
||||
[Route("periods")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> RegenerateHalfCenturiesAsync()
|
||||
{
|
||||
var res = await _ganjoorService.RegenerateHalfCenturiesAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// create new poet
|
||||
/// </summary>
|
||||
|
||||
@ -717,6 +717,12 @@
|
||||
<param name="poet"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.RegenerateHalfCenturiesAsync">
|
||||
<summary>
|
||||
regenerate half centuries
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.CreatePoet(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel)">
|
||||
<summary>
|
||||
create new poet
|
||||
@ -9155,6 +9161,12 @@
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.RegenerateHalfCenturiesAsync">
|
||||
<summary>
|
||||
regenerate half centuries
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IGanjoorTranslationService">
|
||||
<summary>
|
||||
translation service implementation
|
||||
|
||||
@ -640,5 +640,11 @@ namespace RMuseum.Services
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorUserBookmarkViewModel[] Bookmarks)>> GetUserBookmarks(PagingParameterModel paging, Guid userId);
|
||||
|
||||
/// <summary>
|
||||
/// regenerate half centuries
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> RegenerateHalfCenturiesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,8 +5,6 @@ using System;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RMuseum.Services.Implementation
|
||||
@ -225,7 +223,47 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
};
|
||||
|
||||
var poets = await _context.GanjoorPoets.AsNoTracking().Where(p => p.BirthYearInLHijri != 0).OrderBy(p => new { p.BirthYearInLHijri, p.DeathYearInLHijri }).ToArrayAsync();
|
||||
var poets = await _context.GanjoorPoets.AsNoTracking().Where(p => p.BirthYearInLHijri != 0).OrderBy(p => p.BirthYearInLHijri).ToArrayAsync();
|
||||
|
||||
foreach (var poet in poets)
|
||||
{
|
||||
GanjoorHalfCentury period = null;
|
||||
var relatedPeriods = periods.Where(p => p.StartYear <= poet.BirthYearInLHijri && p.EndYear >= poet.DeathYearInLHijri).ToList();
|
||||
if(relatedPeriods.Count == 1)
|
||||
{
|
||||
period = relatedPeriods.First();
|
||||
}
|
||||
else
|
||||
{
|
||||
int maxIntersect = 0;
|
||||
foreach (var p in relatedPeriods)
|
||||
{
|
||||
int intersect = poet.BirthYearInLHijri > p.StartYear ? poet.BirthYearInLHijri - p.StartYear : 0;
|
||||
intersect += (poet.DeathYearInLHijri < p.EndYear ? p.EndYear - poet.DeathYearInLHijri : 0);
|
||||
if(maxIntersect < intersect)
|
||||
{
|
||||
maxIntersect = intersect;
|
||||
period = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(period != null)
|
||||
{
|
||||
if (period.Poets == null)
|
||||
period.Poets = new List<GanjoorPoet>();
|
||||
period.Poets.Add(poet);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var period in periods)
|
||||
{
|
||||
if(period.Poets != null)
|
||||
{
|
||||
_context.Add(period);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user