fix for faal
This commit is contained in:
parent
aad97e72a7
commit
d3d1eb19d4
@ -33,6 +33,8 @@ namespace RMuseum.Services.Implementation
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var poem = await _context.GanjoorPoems.Include(p => p.Cat).Where(p => p.Id == id).SingleOrDefaultAsync();
|
var poem = await _context.GanjoorPoems.Include(p => p.Cat).Where(p => p.Id == id).SingleOrDefaultAsync();
|
||||||
|
if (poem == null)
|
||||||
|
return new RServiceResult<GanjoorPoem>(null);
|
||||||
var cat = poem.Cat;
|
var cat = poem.Cat;
|
||||||
while(cat != null)
|
while(cat != null)
|
||||||
{
|
{
|
||||||
@ -135,6 +137,20 @@ namespace RMuseum.Services.Implementation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int _GetRandomPoemId()
|
||||||
|
{
|
||||||
|
//this is magic number based method!
|
||||||
|
int startPoemId = 2130;
|
||||||
|
int endPoemId = 2634 + 1; //one is added for مژده ای دل که مسیحا نفسی میآید
|
||||||
|
Random r = new Random(DateTime.Now.Millisecond);
|
||||||
|
int poemId = r.Next(startPoemId, endPoemId);
|
||||||
|
if (poemId == endPoemId)
|
||||||
|
{
|
||||||
|
poemId = 33179;//مژده ای دل که مسیحا نفسی میآید
|
||||||
|
}
|
||||||
|
return poemId;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// get a random poem from hafez
|
/// get a random poem from hafez
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -143,22 +159,26 @@ namespace RMuseum.Services.Implementation
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//this is magic number based method!
|
int poemId = _GetRandomPoemId();
|
||||||
int startPoemId = 2130;
|
var poem = (await GetPoemById(poemId)).Result;
|
||||||
int endPoemId = 2634 + 1; //one is added for مژده ای دل که مسیحا نفسی میآید
|
PublicRecitationViewModel[] recitations = poem == null ? new PublicRecitationViewModel[] { } : (await GetPoemRecitations(poemId)).Result;
|
||||||
Random r = new Random(DateTime.Now.Millisecond);
|
int loopPreventer = 0;
|
||||||
int poemId = r.Next(startPoemId, endPoemId);
|
while (poem == null || recitations.Length == 0)
|
||||||
if(poemId == endPoemId)
|
|
||||||
{
|
{
|
||||||
poemId = 33179;//مژده ای دل که مسیحا نفسی میآید
|
poem = (await GetPoemById(poemId)).Result;
|
||||||
|
recitations = poem == null ? new PublicRecitationViewModel[] { } : (await GetPoemRecitations(poemId)).Result;
|
||||||
|
loopPreventer++;
|
||||||
|
if (loopPreventer > 5)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RServiceResult<GanjoorPoemCompleteViewModel>
|
return new RServiceResult<GanjoorPoemCompleteViewModel>
|
||||||
(
|
(
|
||||||
new GanjoorPoemCompleteViewModel()
|
new GanjoorPoemCompleteViewModel()
|
||||||
{
|
{
|
||||||
Poem = (await GetPoemById(poemId)).Result,
|
Poem = poem,
|
||||||
Recitations = (await GetPoemRecitations(poemId)).Result,
|
Recitations = recitations,
|
||||||
Images = (await GetPoemImages(poemId)).Result
|
Images = null //no usage for now, so do not waste resources
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user