/
GanjoorService-QuotedPoems.cs
1789 lines (1627 loc) · 97 KB
/
GanjoorService-QuotedPoems.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using DNTPersianUtils.Core;
using Microsoft.EntityFrameworkCore;
using RMuseum.DbContext;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
using RSecurityBackend.Models.Generic;
using RSecurityBackend.Models.Generic.Db;
using RSecurityBackend.Services.Implementation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RMuseum.Services.Implementation
{
/// <summary>
/// IGanjoorService implementation
/// </summary>
public partial class GanjoorService : IGanjoorService
{
/// <summary>
/// moderate quoted poems
/// </summary>
/// <param name="model"></param>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> ModerateGanjoorQuotedPoemAsync(GanjoorQuotedPoemModerationViewModel model, Guid userId)
{
try
{
var dbQuoted = await _context.GanjoorQuotedPoems.Where(q => q.Id == model.Id).SingleAsync();
dbQuoted.ReviewNote = model.ReviewNote;
dbQuoted.Published = model.Approved;
dbQuoted.Rejected = !model.Approved;
dbQuoted.ReviewerUserId = userId;
dbQuoted.ReviewDate = DateTime.Now;
_context.Update(dbQuoted);
await _context.SaveChangesAsync();
if (model.Approved)
{
if (dbQuoted.ClaimedByBothPoets)
{
var poem = await _context.GanjoorPoems.Where(p => p.Id == dbQuoted.PoemId).SingleAsync();
if (poem.ClaimedByMultiplePoets == false)
{
poem.ClaimedByMultiplePoets = true;
_context.Update(poem);
await _context.SaveChangesAsync();
}
}
var allRelateds = await _context.GanjoorQuotedPoems.Where(p => p.PoemId == dbQuoted.PoemId && p.RelatedPoemId == dbQuoted.RelatedPoemId && p.Published).ToListAsync();
foreach (var rel in allRelateds)
{
rel.SamePoemsQuotedCount = allRelateds.Count;
_context.Update(rel);
await _context.SaveChangesAsync();
}
if (dbQuoted.Published && dbQuoted.RelatedPoetId != null)
{
var page = await _context.GanjoorPages.AsNoTracking().Where(p => p.PoetId == dbQuoted.PoetId && p.SecondPoetId == dbQuoted.RelatedPoetId).SingleOrDefaultAsync();
if (page != null)
{
StartRegeneratingRelatedPoemsPageAsync(userId, dbQuoted.PoetId, (int)dbQuoted.RelatedPoetId);
}
if (dbQuoted.RelatedPoemId != null)
{
var reverseAdded = await _context.GanjoorQuotedPoems.AsNoTracking()
.AnyAsync(q => q.PoemId == dbQuoted.RelatedPoemId &&
q.RelatedPoemId == dbQuoted.PoemId
&&
q.CoupletIndex == dbQuoted.RelatedCoupletIndex
&&
q.RelatedCoupletIndex == dbQuoted.CoupletIndex
&&
q.Rejected == false
);
if (!reverseAdded)
{
var poet = await _context.GanjoorPoets.AsNoTracking().Where(p => p.Id == dbQuoted.PoetId).SingleAsync();
var poetCat = await _context.GanjoorCategories.AsNoTracking().Where(c => c.PoetId == poet.Id && c.ParentId == null).SingleAsync();
var poem = await _context.GanjoorPoems.AsNoTracking().Where(p => p.Id == dbQuoted.PoemId).SingleAsync();
GanjoorQuotedPoem reverseRelation = new GanjoorQuotedPoem()
{
PoemId = (int)dbQuoted.RelatedPoemId,
PoetId = (int)dbQuoted.RelatedPoetId,
RelatedPoetId = dbQuoted.PoetId,
RelatedPoemId = dbQuoted.PoemId,
IsPriorToRelated = !dbQuoted.IsPriorToRelated,
ChosenForMainList = false == await _context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == dbQuoted.RelatedPoemId && p.RelatedPoemId == dbQuoted.PoemId && p.Published == true).AnyAsync(),
CachedRelatedPoemPoetDeathYearInLHijri = poet.DeathYearInLHijri,
CachedRelatedPoemPoetName = poet.Nickname,
CachedRelatedPoemPoetUrl = poetCat.FullUrl,
CachedRelatedPoemPoetImage = $"/api/ganjoor/poet/image{poetCat.FullUrl}.gif",
CachedRelatedPoemFullTitle = poem.FullTitle,
CachedRelatedPoemFullUrl = poem.FullUrl,
SortOrder = 1000,
Note = dbQuoted.Note,
Published = false,
RelatedCoupletVerse1 = dbQuoted.CoupletVerse1,
RelatedCoupletVerse1ShouldBeEmphasized = dbQuoted.CoupletVerse1ShouldBeEmphasized,
RelatedCoupletVerse2 = dbQuoted.CoupletVerse2,
RelatedCoupletVerse2ShouldBeEmphasized = dbQuoted.CoupletVerse2ShouldBeEmphasized,
RelatedCoupletIndex = dbQuoted.CoupletIndex,
CoupletVerse1 = dbQuoted.RelatedCoupletVerse1,
CoupletVerse1ShouldBeEmphasized = dbQuoted.RelatedCoupletVerse1ShouldBeEmphasized,
CoupletVerse2 = dbQuoted.RelatedCoupletVerse2,
CoupletVerse2ShouldBeEmphasized = dbQuoted.RelatedCoupletVerse2ShouldBeEmphasized,
CoupletIndex = dbQuoted.RelatedCoupletIndex,
ClaimedByBothPoets = dbQuoted.ClaimedByBothPoets,
IndirectQuotation = dbQuoted.IndirectQuotation,
SamePoemsQuotedCount = await _context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == dbQuoted.RelatedPoemId && p.RelatedPoemId == dbQuoted.PoemId && p.Published == true).AnyAsync() ?
1 + await _context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == dbQuoted.RelatedPoemId && p.RelatedPoemId == dbQuoted.PoemId && p.Published == true).CountAsync() : 1,
SuggestedById = dbQuoted.SuggestedById,
SuggestionDate = dbQuoted.SuggestionDate,
};
_context.Add(reverseRelation);
await _context.SaveChangesAsync();
await ModerateGanjoorQuotedPoemAsync
(
new GanjoorQuotedPoemModerationViewModel()
{
Id = reverseRelation.Id,
Approved = true,
ReviewNote = "درج خودکار معکوس پیشنهاد"
},
userId
);
}
}
}
}
await _notificationService.PushNotification((Guid)dbQuoted.SuggestedById,
"بررسی مشق شعر پیشنهادی شما",
$"با سپاس از زحمت و همت شما مشق شعر پیشنهادیتان برای <a href=\"https://ganjoor.net{dbQuoted.CachedRelatedPoemFullUrl}\" target=\"_blank\">{dbQuoted.CachedRelatedPoemFullTitle}</a> بررسی شد.{Environment.NewLine}" +
$"جهت مشاهدهٔ نتیجهٔ بررسی در میز کاربری خود بخش «<a href=\"https://ganjoor.net/User/MySuggestedQuotes\">مشق شعرهای پیشنهادی من</a>» را مشاهده بفرمایید.{Environment.NewLine}"
);
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// suggest new quote
/// </summary>
/// <param name="quoted"></param>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorQuotedPoemViewModel>> SuggestGanjoorQuotedPoemAsync(GanjoorQuotedPoemViewModel quoted, Guid userId)
{
try
{
if (await _context.GanjoorQuotedPoems.AsNoTracking()
.Where(q =>
q.PoemId == quoted.PoemId
&&
q.RelatedPoemId != null && q.RelatedPoemId == quoted.RelatedPoemId
&&
q.CoupletIndex == quoted.CoupletIndex
&&
q.RelatedCoupletIndex != null && q.RelatedCoupletIndex == quoted.RelatedCoupletIndex
&&
q.Rejected == false
).AnyAsync())
{
return new RServiceResult<GanjoorQuotedPoemViewModel>(null, "این نقل قول پیشتر پیشنهاد شده است.");
}
if (quoted.RelatedPoemId == null)
{
if (string.IsNullOrEmpty(quoted.RelatedCoupletVerse1) || string.IsNullOrEmpty(quoted.RelatedCoupletVerse2))
{
return new RServiceResult<GanjoorQuotedPoemViewModel>(null, "اگر شعر از گنجور انتخاب نشده باید متن مصرع اول و دوم را بنویسید.");
}
if (string.IsNullOrEmpty(quoted.CachedRelatedPoemPoetName))
{
return new RServiceResult<GanjoorQuotedPoemViewModel>(null, "اگر شعر از گنجور انتخاب نشده باید نام شاعر مرتبط را بنویسید.");
}
if (string.IsNullOrEmpty(quoted.CachedRelatedPoemFullTitle))
{
quoted.CachedRelatedPoemFullTitle = quoted.CachedRelatedPoemPoetName;
}
}
GanjoorQuotedPoem dbQuoted = new GanjoorQuotedPoem()
{
Id = quoted.Id,
PoemId = quoted.PoemId,
Poem = quoted.Poem,
RelatedPoemId = quoted.RelatedPoemId,
IsPriorToRelated = quoted.IsPriorToRelated,
ChosenForMainList = quoted.ChosenForMainList,
SortOrder = quoted.SortOrder,
CachedRelatedPoemPoetDeathYearInLHijri = quoted.CachedRelatedPoemPoetDeathYearInLHijri,
CachedRelatedPoemPoetName = quoted.CachedRelatedPoemPoetName,
CachedRelatedPoemPoetUrl = quoted.CachedRelatedPoemPoetUrl,
CachedRelatedPoemPoetImage = quoted.CachedRelatedPoemPoetImage,
CachedRelatedPoemFullTitle = quoted.CachedRelatedPoemFullTitle,
CachedRelatedPoemFullUrl = quoted.CachedRelatedPoemFullUrl,
CoupletVerse1 = quoted.CoupletVerse1,
CoupletVerse1ShouldBeEmphasized = quoted.CoupletVerse1ShouldBeEmphasized,
CoupletVerse2 = quoted.CoupletVerse2,
CoupletVerse2ShouldBeEmphasized = quoted.CoupletVerse2ShouldBeEmphasized,
CoupletIndex = quoted.CoupletIndex,
RelatedCoupletVerse1 = quoted.RelatedCoupletVerse1,
RelatedCoupletVerse1ShouldBeEmphasized = quoted.RelatedCoupletVerse1ShouldBeEmphasized,
RelatedCoupletVerse2 = quoted.RelatedCoupletVerse2,
RelatedCoupletVerse2ShouldBeEmphasized = quoted.RelatedCoupletVerse2ShouldBeEmphasized,
RelatedCoupletIndex = quoted.RelatedCoupletIndex,
Note = quoted.Note,
Published = false,
SamePoemsQuotedCount = 1,
ClaimedByBothPoets = quoted.ClaimedByBothPoets,
PoetId = quoted.PoetId,
RelatedPoetId = quoted.RelatedPoetId,
IndirectQuotation = quoted.IndirectQuotation,
SuggestedById = userId,
SuggestionDate = DateTime.Now,
};
_context.Add(dbQuoted);
await _context.SaveChangesAsync();
return new RServiceResult<GanjoorQuotedPoemViewModel>(new GanjoorQuotedPoemViewModel(dbQuoted));
}
catch (Exception exp)
{
return new RServiceResult<GanjoorQuotedPoemViewModel>(null, exp.ToString());
}
}
/// <summary>
/// get user or all quoted suggestions
/// </summary>
/// <param name="userId">if sent empty returns all suggestions</param>
/// <param name="paging"></param>
/// <returns></returns>
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorQuotedPoemViewModel[] Items)>> GetUserQuotedSuggestionsAsync(Guid userId, PagingParameterModel paging)
{
var source = from dbSuggestion in
_context.GanjoorQuotedPoems.AsNoTracking()
where userId == Guid.Empty || dbSuggestion.SuggestedById == userId
orderby dbSuggestion.Id descending
select
dbSuggestion;
(PaginationMetadata PagingMeta, GanjoorQuotedPoem[] Items) dbPaginatedResult =
await QueryablePaginator<GanjoorQuotedPoem>.Paginate(source, paging);
List<GanjoorQuotedPoemViewModel> list = new List<GanjoorQuotedPoemViewModel>();
foreach (var dbCorrection in dbPaginatedResult.Items)
{
list.Add
(
new GanjoorQuotedPoemViewModel(dbCorrection)
);
}
return new RServiceResult<(PaginationMetadata, GanjoorQuotedPoemViewModel[])>
((dbPaginatedResult.PagingMeta, list.ToArray()));
}
/// <summary>
/// next unmoderated quoted poem
/// </summary>
/// <param name="skip"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorQuotedPoemViewModel>> GetNextUnmoderatedGanjoorQuotedPoemAsync(int skip)
{
try
{
var r = await
_context.GanjoorQuotedPoems
.AsNoTracking()
.Where(r => r.Published == false && r.Rejected == false)
.OrderBy(r => r.Id)
.Skip(skip)
.FirstOrDefaultAsync();
return new RServiceResult<GanjoorQuotedPoemViewModel>(r == null ? null : new GanjoorQuotedPoemViewModel(r, true));
}
catch (Exception exp)
{
return new RServiceResult<GanjoorQuotedPoemViewModel>(null, exp.ToString());
}
}
/// <summary>
/// unmoderated quoted poems count
/// </summary>
/// <returns></returns>
public async Task<RServiceResult<int>> GetUnmoderatedGanjoorQuotedsCountAsync()
{
try
{
return new RServiceResult<int>(
await
_context.GanjoorQuotedPoems
.AsNoTracking()
.Where(r => r.Published == false && r.Rejected == false)
.CountAsync()
);
}
catch (Exception exp)
{
return new RServiceResult<int>(-1, exp.ToString());
}
}
/// <summary>
/// discover related poems
/// </summary>
/// <param name="poetId"></param>
/// <param name="relatedPoetId"></param>
/// <param name="breakOnFirstSimilar"></param>
/// <param name="relatedSubCatId"></param>
/// <param name="insertReverse"></param>
/// <returns></returns>
public RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar, int? relatedSubCatId, bool insertReverse)
{
try
{
_backgroundTaskQueue.QueueBackgroundWorkItem
(
async token =>
{
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
{
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
var job = (await jobProgressServiceEF.NewJob($"StartDiscoverRelatedPoems({poetId}, {relatedPoetId})", "Query data")).Result;
try
{
await _DiscoverRelatedPoemsAsync(context, poetId, relatedPoetId, insertReverse, jobProgressServiceEF, job, breakOnFirstSimilar, relatedSubCatId);
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
}
catch (Exception exp)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
}
}
});
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
private static bool AreSimilar(string str1, string str2, bool reverse)
{
if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2))
return false;
string[] words2 = str2.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int total = words2.Length;
int found = 0;
for (int i = 0; i < total; i++)
{
if (str1.IndexOf(words2[i]) != -1)
found++;
}
if (!reverse)
return (float)found / total > 0.7f;
return (float)found / total > 0.7f && AreSimilar(str2, str1, false);
}
private async Task<RServiceResult<bool>> _DiscoverRelatedPoemsAsync(RMuseumDbContext context, int poetId, int relatedPoetId, bool insertReverse, LongRunningJobProgressServiceEF jobProgressServiceEF, RLongRunningJobStatus job, bool breakOnFirstSimilar, int? relatedSubCatId)
{
DiscoverQuotedQueueItem discoverQuotedQueueItem = await context.DiscoverQuotedQueueItems.Where(i => i.PoetId == poetId && i.RelatedPoetId == relatedPoetId).SingleOrDefaultAsync();
if (discoverQuotedQueueItem == null)
{
discoverQuotedQueueItem = new DiscoverQuotedQueueItem()
{
PoetId = poetId,
PoemId = 0,
RelatedPoetId = relatedPoetId,
RelatedPoemId = 0
};
context.Add(discoverQuotedQueueItem);
await context.SaveChangesAsync();
}
var poet = await context.GanjoorPoets.AsNoTracking().Where(p => p.Id == poetId).SingleAsync();
var poetCat = await context.GanjoorCategories.AsNoTracking().Where(c => c.PoetId == poetId && c.ParentId == null).SingleAsync();
var relatedPoet = await context.GanjoorPoets.AsNoTracking().Where(p => p.Id == relatedPoetId).SingleAsync();
var relatedPoetCat = await context.GanjoorCategories.AsNoTracking().Where(c => c.PoetId == relatedPoetId && c.ParentId == null).SingleAsync();
bool isPriorToRelated = poet.DeathYearInLHijri < relatedPoet.DeathYearInLHijri;
List<int> catIdList = new List<int>();
if (relatedSubCatId != null)
{
catIdList.Add((int)relatedSubCatId);
await _populateCategoryChildren(context, (int)relatedSubCatId, catIdList);
}
var poems = await context.GanjoorPoems.AsNoTracking().Include(p => p.Cat).Where(p => p.Id >= discoverQuotedQueueItem.PoemId && p.Cat.PoetId == poetId).OrderBy(p => p.Id).ToListAsync();
foreach (var poem in poems)
{
discoverQuotedQueueItem.PoemId = poem.Id;
context.Update(discoverQuotedQueueItem);
await jobProgressServiceEF.UpdateJob(job.Id, poem.Id);
var verses = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == poem.Id
&& v.VersePosition != VersePosition.Paragraph
&& v.VersePosition != VersePosition.Single
&& v.VersePosition != VersePosition.Comment
&& v.CoupletIndex != null
).OrderBy(v => v.VOrder).ToListAsync();
var relatedPoems = await context.GanjoorPoems.AsNoTracking().Include(p => p.Cat)
.Where(p => p.Id >= discoverQuotedQueueItem.RelatedPoemId && p.Cat.PoetId == relatedPoetId && (relatedSubCatId == null || catIdList.Contains(p.CatId)))
.OrderBy(p => p.Id).ToListAsync();
foreach (var otherPoem in relatedPoems)
{
discoverQuotedQueueItem.RelatedPoemId = otherPoem.Id;
context.Update(discoverQuotedQueueItem);
await jobProgressServiceEF.UpdateJob(job.Id, poem.Id, otherPoem.Id.ToString());
var relatedVerses = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == otherPoem.Id
&& v.VersePosition != VersePosition.Paragraph
&& v.VersePosition != VersePosition.Single
&& v.VersePosition != VersePosition.Comment
&& v.CoupletIndex != null
).OrderBy(v => v.VOrder).ToListAsync();
foreach (var verse in verses)
{
string text = LanguageUtils.MakeTextSearchable(verse.Text);
foreach (var relatedVerse in relatedVerses)
{
if (AreSimilar(text, LanguageUtils.MakeTextSearchable(relatedVerse.Text), true))
{
var alreadyAdded = await context.GanjoorQuotedPoems.AsNoTracking()
.AnyAsync(q => q.PoemId == poem.Id &&
q.RelatedPoemId == otherPoem.Id
&&
q.CoupletIndex == verse.CoupletIndex
&&
q.RelatedCoupletIndex == relatedVerse.CoupletIndex
);
if (alreadyAdded) continue;
GanjoorQuotedPoem relatedPoem = new GanjoorQuotedPoem()
{
PoemId = poem.Id,
PoetId = poetId,
RelatedPoetId = relatedPoetId,
RelatedPoemId = otherPoem.Id,
IsPriorToRelated = isPriorToRelated,
ChosenForMainList = false == await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == poem.Id && p.RelatedPoemId == otherPoem.Id && p.Published == true).AnyAsync(),
CachedRelatedPoemPoetDeathYearInLHijri = relatedPoet.DeathYearInLHijri,
CachedRelatedPoemPoetName = relatedPoet.Nickname,
CachedRelatedPoemPoetUrl = relatedPoetCat.FullUrl,
CachedRelatedPoemPoetImage = $"/api/ganjoor/poet/image{relatedPoetCat.FullUrl}.gif",
CachedRelatedPoemFullTitle = otherPoem.FullTitle,
CachedRelatedPoemFullUrl = otherPoem.FullUrl,
SortOrder = 1000,
Note = "",
Published = false,
ClaimedByBothPoets = false,
IndirectQuotation = false,
SamePoemsQuotedCount = await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == poem.Id && p.RelatedPoemId == otherPoem.Id && p.Published == true).AnyAsync() ?
1 + await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == poem.Id && p.RelatedPoemId == otherPoem.Id && p.Published == true).CountAsync() : 1,
RelatedCoupletVerse1 = relatedVerses.Where(v => v.CoupletIndex == relatedVerse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[0].Text,
RelatedCoupletVerse1ShouldBeEmphasized = relatedVerses.Where(v => v.CoupletIndex == relatedVerse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[0].VOrder == relatedVerse.VOrder,
RelatedCoupletVerse2 = relatedVerses.Where(v => v.CoupletIndex == relatedVerse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[1].Text,
RelatedCoupletVerse2ShouldBeEmphasized = relatedVerses.Where(v => v.CoupletIndex == relatedVerse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[1].VOrder == relatedVerse.VOrder,
RelatedCoupletIndex = relatedVerse.CoupletIndex,
CoupletVerse1 = verses.Where(v => v.CoupletIndex == verse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[0].Text,
CoupletVerse1ShouldBeEmphasized = verses.Where(v => v.CoupletIndex == verse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[0].VOrder == verse.VOrder,
CoupletVerse2 = verses.Where(v => v.CoupletIndex == verse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[1].Text,
CoupletVerse2ShouldBeEmphasized = verses.Where(v => v.CoupletIndex == verse.CoupletIndex).OrderBy(v => v.VOrder).ToArray()[1].VOrder == verse.VOrder,
CoupletIndex = verse.CoupletIndex,
};
context.Add(relatedPoem);
await context.SaveChangesAsync();
if (insertReverse)
{
var alreadyAdded2 = await context.GanjoorQuotedPoems.AsNoTracking()
.AnyAsync(q => q.PoemId == otherPoem.Id &&
q.RelatedPoemId == poem.Id
&&
q.CoupletIndex == relatedVerse.CoupletIndex
&&
q.RelatedCoupletIndex == verse.CoupletIndex
);
if (alreadyAdded2) continue;
GanjoorQuotedPoem reverseRelation = new GanjoorQuotedPoem()
{
PoemId = otherPoem.Id,
PoetId = relatedPoet.Id,
RelatedPoetId = poet.Id,
RelatedPoemId = poem.Id,
IsPriorToRelated = !relatedPoem.IsPriorToRelated,
ChosenForMainList = false == await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id && p.Published == true).AnyAsync(),
CachedRelatedPoemPoetDeathYearInLHijri = poet.DeathYearInLHijri,
CachedRelatedPoemPoetName = poet.Nickname,
CachedRelatedPoemPoetUrl = poetCat.FullUrl,
CachedRelatedPoemPoetImage = $"/api/ganjoor/poet/image{poetCat.FullUrl}.gif",
CachedRelatedPoemFullTitle = poem.FullTitle,
CachedRelatedPoemFullUrl = poem.FullUrl,
SortOrder = 1000,
Note = "",
Published = false,
RelatedCoupletVerse1 = relatedPoem.CoupletVerse1,
RelatedCoupletVerse1ShouldBeEmphasized = relatedPoem.CoupletVerse1ShouldBeEmphasized,
RelatedCoupletVerse2 = relatedPoem.CoupletVerse2,
RelatedCoupletVerse2ShouldBeEmphasized = relatedPoem.CoupletVerse2ShouldBeEmphasized,
RelatedCoupletIndex = relatedPoem.CoupletIndex,
CoupletVerse1 = relatedPoem.RelatedCoupletVerse1,
CoupletVerse1ShouldBeEmphasized = relatedPoem.RelatedCoupletVerse1ShouldBeEmphasized,
CoupletVerse2 = relatedPoem.RelatedCoupletVerse2,
CoupletVerse2ShouldBeEmphasized = relatedPoem.RelatedCoupletVerse2ShouldBeEmphasized,
CoupletIndex = relatedPoem.RelatedCoupletIndex,
ClaimedByBothPoets = false,
IndirectQuotation = false,
SamePoemsQuotedCount = await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id && p.Published == true).AnyAsync() ?
1 + await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id && p.Published == true).CountAsync() : 1
};
context.Add(reverseRelation);
await context.SaveChangesAsync();
}
if (breakOnFirstSimilar)
break;
}
}
}
}
}
return new RServiceResult<bool>(true);
}
/// <summary>
/// regenerate related poems pages
/// </summary>
/// <param name="editingUserId"></param>
/// <returns></returns>
public RServiceResult<bool> StartRegeneratingRelatedPoemsPages(Guid editingUserId)
{
try
{
_backgroundTaskQueue.QueueBackgroundWorkItem
(
async token =>
{
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
{
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
var job = (await jobProgressServiceEF.NewJob($"StartRegeneratingRelatedPoemsPagesAsync", "Query data")).Result;
try
{
var pages = await context.GanjoorPages.AsNoTracking().Where(p => p.SecondPoetId != null).ToListAsync();
foreach (var page in pages)
{
await jobProgressServiceEF.UpdateJob(job.Id, page.Id, $"StartRegeneratingRelatedPoemsPageAsync({page.PoetId}, {page.SecondPoetId})");
var resPage = await _RegenerateRelatedPoemsPageAsync(editingUserId, context, (int)page.PoetId, (int)page.SecondPoetId);
if(!string.IsNullOrEmpty(resPage.ExceptionString))
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, resPage.ExceptionString);
return;
}
}
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
}
catch (Exception exp)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
}
}
});
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// generate related poems page
/// </summary>
/// <param name="editingUserId"></param>
/// <param name="poetId"></param>
/// <param name="relatedPoetId"></param>
/// <returns></returns>
public RServiceResult<bool> StartRegeneratingRelatedPoemsPageAsync(Guid editingUserId, int poetId, int relatedPoetId)
{
try
{
_backgroundTaskQueue.QueueBackgroundWorkItem
(
async token =>
{
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
{
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
var job = (await jobProgressServiceEF.NewJob($"StartRegeneratingRelatedPoemsPageAsync({poetId}, {relatedPoetId})", "Query data")).Result;
try
{
var resPage = await _RegenerateRelatedPoemsPageAsync(editingUserId, context, poetId, relatedPoetId);
if (!string.IsNullOrEmpty(resPage.ExceptionString))
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, resPage.ExceptionString);
return;
}
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
}
catch (Exception exp)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
}
}
});
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// parse related pages
/// </summary>
/// <param name="editingUserId"></param>
/// <param name="context"></param>
/// <param name="poetId"></param>
/// <param name="relatedPoetId"></param>
/// <returns></returns>
private async Task<RServiceResult<bool>> _RegenerateRelatedPoemsPageAsync(Guid editingUserId, RMuseumDbContext context, int poetId, int relatedPoetId)
{
var page = await context.GanjoorPages.AsNoTracking().Where(p => p.PoetId == poetId && p.SecondPoetId == relatedPoetId).SingleOrDefaultAsync();
if (page == null)
{
return new RServiceResult<bool>(false, $"No page for {poetId} - {relatedPoetId}");
}
try
{
var poet = await context.GanjoorPoets.AsNoTracking().Where(p => p.Id == page.PoetId).SingleAsync();
var poetCat = await context.GanjoorCategories.AsNoTracking().Where(c => c.PoetId == poet.Id && c.ParentId == null).SingleAsync();
var relatedPoet = await context.GanjoorPoets.AsNoTracking().Where(p => p.Id == page.SecondPoetId).SingleAsync();
var relatedPoetCat = await context.GanjoorCategories.AsNoTracking().Where(c => c.PoetId == relatedPoet.Id && c.ParentId == null).SingleAsync();
string html = "";
var claimedByBothList = await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoetId == poetId && p.RelatedPoetId == relatedPoetId && p.ClaimedByBothPoets && p.Published).OrderBy(p => p.PoemId).ThenBy(p => p.RelatedPoemId).ToListAsync();
var claimedByBothListNotInGanjoor = await context.GanjoorQuotedPoems.AsNoTracking().Where(
p =>
(
(p.PoetId == poetId && p.CachedRelatedPoemFullUrl == $"https://ganjoor.net{relatedPoetCat.FullUrl}")
||
(p.PoetId == relatedPoetId && p.CachedRelatedPoemFullUrl == $"https://ganjoor.net{poetCat.FullUrl}")
)
&& p.RelatedPoetId == null && p.ClaimedByBothPoets && p.Published
).OrderBy(p => p.PoemId).ToListAsync();
if (claimedByBothList.Any() || claimedByBothListNotInGanjoor.Any())
{
html += $"<p>فهرست زیر شامل اشعاری است که در نسخههای دیوانهای هر دو سخنور آمده است و به هر دو منتسب است:</p>{Environment.NewLine}";
html += $"<br style=\"clear:both;\">{Environment.NewLine}";
html += $"<ol>{Environment.NewLine}";
foreach (var quotedPoem in claimedByBothList)
{
var poem = await context.GanjoorPoems.AsNoTracking().Where(p => p.Id == quotedPoem.PoemId).SingleAsync();
html += $"<li>{Environment.NewLine}";
html += $"<h3>{Environment.NewLine}";
html += $"<a href=\"{poem.FullUrl}\">{poem.FullTitle}</a> :: <a href=\"{quotedPoem.CachedRelatedPoemFullUrl}\">{quotedPoem.CachedRelatedPoemFullTitle}</a>{Environment.NewLine}";
html += $"</h3>{Environment.NewLine}";
html += $"<p>{poet.Nickname} (بیت {(quotedPoem.CoupletIndex + 1).ToPersianNumbers()}): ";
if (quotedPoem.CoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse1}</strong>";
}
else
{
html += quotedPoem.CoupletVerse1;
}
html += " - ";
if (quotedPoem.CoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse2}</strong>";
}
else
{
html += quotedPoem.CoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
html += $"<p>{quotedPoem.CachedRelatedPoemPoetName} (بیت {(quotedPoem.RelatedCoupletIndex + 1).ToPersianNumbers()}): ";
if (quotedPoem.RelatedCoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse1}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse1;
}
html += " - ";
if (quotedPoem.RelatedCoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse2}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
if (!string.IsNullOrEmpty(quotedPoem.Note))
{
html += $"<div class=\"notice\">{quotedPoem.Note}</div>{Environment.NewLine}";
}
html += $"</li>{Environment.NewLine}";
}
foreach (var quotedPoem in claimedByBothListNotInGanjoor)
{
var poem = await context.GanjoorPoems.AsNoTracking().Where(p => p.Id == quotedPoem.PoemId).SingleAsync();
html += $"<li>{Environment.NewLine}";
html += $"<h3>{Environment.NewLine}";
html += $"<a href=\"{poem.FullUrl}\">{poem.FullTitle}</a> :: {quotedPoem.CachedRelatedPoemFullTitle}{Environment.NewLine}";
html += $"</h3>{Environment.NewLine}";
html += $"<p>{poet.Nickname} (بیت {(quotedPoem.CoupletIndex + 1).ToPersianNumbers()}): ";
if (quotedPoem.CoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse1}</strong>";
}
else
{
html += quotedPoem.CoupletVerse1;
}
html += " - ";
if (quotedPoem.CoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse2}</strong>";
}
else
{
html += quotedPoem.CoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
html += $"<p>";
if (quotedPoem.RelatedCoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse1}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse1;
}
html += " - ";
if (quotedPoem.RelatedCoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse2}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
if (!string.IsNullOrEmpty(quotedPoem.Note))
{
html += $"<div class=\"notice\">{quotedPoem.Note}</div>{Environment.NewLine}";
}
html += $"</li>{Environment.NewLine}";
}
html += $"</ol>{Environment.NewLine}";
html += $"<br style=\"clear:both;\">{Environment.NewLine}";
}
var normalRelatedPoems = await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoetId == poetId && p.RelatedPoetId == relatedPoetId && p.ClaimedByBothPoets == false && p.Published).OrderBy(p => p.PoemId).ThenBy(p => p.CoupletIndex).ToListAsync();
var normalRelatedPoemsNotInGanjoor = await context.GanjoorQuotedPoems.AsNoTracking().Where
(p =>
(
(p.PoetId == poetId && p.CachedRelatedPoemFullUrl == $"https://ganjoor.net{relatedPoetCat.FullUrl}")
||
(p.PoetId == relatedPoetId && p.CachedRelatedPoemFullUrl == $"https://ganjoor.net{poetCat.FullUrl}")
)
&&
p.RelatedPoetId == null && p.ClaimedByBothPoets == false && p.Published
).OrderBy(p => p.PoemId).ToListAsync();
if (normalRelatedPoems.Any() || normalRelatedPoemsNotInGanjoor.Any())
{
html += $"<p>در این بخش شعرهایی را فهرست کردهایم که در آنها {poet.Nickname} مصرع یا بیتی از {relatedPoet.Nickname} را عیناً نقل قول کرده است:</p>{Environment.NewLine}";
html += $"<br style=\"clear:both;\">{Environment.NewLine}";
html += $"<ol>{Environment.NewLine}";
foreach (var quotedPoem in normalRelatedPoems)
{
var poem = await context.GanjoorPoems.AsNoTracking().Where(p => p.Id == quotedPoem.PoemId).SingleAsync();
html += $"<li>{Environment.NewLine}";
html += $"<h3>{Environment.NewLine}";
html += $"<a href=\"{poem.FullUrl}\">{poem.FullTitle}</a> :: <a href=\"{quotedPoem.CachedRelatedPoemFullUrl}\">{quotedPoem.CachedRelatedPoemFullTitle}</a>{Environment.NewLine}";
html += $"</h3>{Environment.NewLine}";
html += $"<p>{poet.Nickname} (بیت {(quotedPoem.CoupletIndex + 1).ToPersianNumbers()}): ";
if (quotedPoem.CoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse1}</strong>";
}
else
{
html += quotedPoem.CoupletVerse1;
}
html += " - ";
if (quotedPoem.CoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse2}</strong>";
}
else
{
html += quotedPoem.CoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
html += $"<p>{quotedPoem.CachedRelatedPoemPoetName} (بیت {(quotedPoem.RelatedCoupletIndex + 1).ToPersianNumbers()}): ";
if (quotedPoem.RelatedCoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse1}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse1;
}
html += " - ";
if (quotedPoem.RelatedCoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse2}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
if (!string.IsNullOrEmpty(quotedPoem.Note))
{
html += $"<div class=\"notice\">{quotedPoem.Note}</div>{Environment.NewLine}";
}
html += $"</li>{Environment.NewLine}";
}
foreach (var quotedPoem in normalRelatedPoemsNotInGanjoor)
{
var poem = await context.GanjoorPoems.AsNoTracking().Where(p => p.Id == quotedPoem.PoemId).SingleAsync();
html += $"<li>{Environment.NewLine}";
html += $"<h3>{Environment.NewLine}";
html += $"<a href=\"{poem.FullUrl}\">{poem.FullTitle}</a> :: {quotedPoem.CachedRelatedPoemFullTitle}{Environment.NewLine}";
html += $"</h3>{Environment.NewLine}";
html += $"<p>{poet.Nickname} (بیت {(quotedPoem.CoupletIndex + 1).ToPersianNumbers()}): ";
if (quotedPoem.CoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse1}</strong>";
}
else
{
html += quotedPoem.CoupletVerse1;
}
html += " - ";
if (quotedPoem.CoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.CoupletVerse2}</strong>";
}
else
{
html += quotedPoem.CoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
html += $"<p>";
if (quotedPoem.RelatedCoupletVerse1ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse1}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse1;
}
html += " - ";
if (quotedPoem.RelatedCoupletVerse2ShouldBeEmphasized)
{
html += $"<strong>{quotedPoem.RelatedCoupletVerse2}</strong>";
}
else
{
html += quotedPoem.RelatedCoupletVerse2;
}
html += $"</p>{Environment.NewLine}";
if (!string.IsNullOrEmpty(quotedPoem.Note))
{
html += $"<div class=\"notice\">{quotedPoem.Note}</div>{Environment.NewLine}";
}
html += $"</li>{Environment.NewLine}";
}
html += $"</ol>{Environment.NewLine}";
html += $"<br style=\"clear:both;\">{Environment.NewLine}";
}
var poemSections = await context.GanjoorPoemSections.AsNoTracking()
.Include(s => s.Poem).ThenInclude(p => p.Cat)
.Include(s => s.GanjoorMetre)
.Where(s => s.SectionType == PoemSectionType.WholePoem && s.Poem.Cat.PoetId == poetId && s.GanjoorMetreId != null && !string.IsNullOrEmpty(s.RhymeLetters))
.OrderBy(s => s.PoemId)
.ToListAsync();
if (poemSections.Any())
{
var relatedPoemSections = await context.GanjoorPoemSections.AsNoTracking()
.Include(s => s.Poem).ThenInclude(p => p.Cat)
.Include(s => s.GanjoorMetre)
.Where(s => s.SectionType == PoemSectionType.WholePoem && s.Poem.Cat.PoetId == relatedPoetId && s.GanjoorMetreId != null && !string.IsNullOrEmpty(s.RhymeLetters))
.OrderBy(s => s.PoemId)
.ToListAsync();
if (relatedPoemSections.Any())
{
Dictionary<(int, string), (List<GanjoorPoemSection>, List<GanjoorPoemSection>)> list = [];
foreach (var poemSection in poemSections)
{
var relatedPoemList = relatedPoemSections.Where(s => s.GanjoorMetreId == poemSection.GanjoorMetreId && s.RhymeLetters == poemSection.RhymeLetters).ToList();
if (!relatedPoemList.Any())
{
continue;
}
if (!list.TryGetValue(((int)poemSection.GanjoorMetreId, poemSection.RhymeLetters), out (List<GanjoorPoemSection>, List<GanjoorPoemSection>) poemsList))
{
poemsList = (new List<GanjoorPoemSection>(), relatedPoemList);
list.Add
(
((int)poemSection.GanjoorMetreId, poemSection.RhymeLetters), poemsList
);
}
poemsList.Item1.Add(poemSection);
}
if (list.Any())
{
html += $"<hr />{Environment.NewLine}";
html += $"<p>در این بخش مجموعه شعرهایی از دو شاعر را که توأماً هموزن و همقافیه هستند در گروههای مجزا فهرست کردهایم: </p>{Environment.NewLine}";
html += $"<br style=\"clear:both;\">{Environment.NewLine}";
html += $"<ol>{Environment.NewLine}";
foreach (var pair in list.Values)
{
html += $"<li>{Environment.NewLine}";
foreach (var section in pair.Item1)
{
var verses = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == section.PoemId && v.SectionIndex1 == section.Index).OrderBy(v => v.VOrder).Take(2).ToListAsync();
if(verses.Any())