From 7d9ae00eec11f1d580b7dea9a5700ea3cf965e5d Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Wed, 5 May 2021 19:29:18 +0430 Subject: [PATCH] #110 refactoring --- RMuseum/RMuseum.xml | 15 +++++++ .../Services/Implementation/GanjoorService.cs | 44 ++++++++++++------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 9a304cf4..832a4007 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -7839,12 +7839,27 @@ + + + random poem id from hafez sonnets + + + get a random poem from hafez + + + older search method + + + + + + Get Similar Poems accroding to prosody and rhyme informations diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index a4793643..8c468adb 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -1031,21 +1031,7 @@ namespace RMuseum.Services.Implementation } } - private int _GetRandomPoemId() - { - //this is magic number based method! - int startPoemId = 2130; - int endPoemId = 2624 + 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; - } - - /// + /// /// Get Poem By Url /// /// @@ -1602,6 +1588,25 @@ namespace RMuseum.Services.Implementation } + /// + /// random poem id from hafez sonnets + /// + /// + private int _GetRandomPoemIdFromHafezSonnets() + { + //this is magic number based method! + int startPoemId = 2130; + int endPoemId = 2624 + 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; + } + + /// /// get a random poem from hafez @@ -1611,7 +1616,7 @@ namespace RMuseum.Services.Implementation { try { - int poemId = _GetRandomPoemId(); + int poemId = _GetRandomPoemIdFromHafezSonnets(); var poem = await _context.GanjoorPoems.Where(p => p.Id == poemId).SingleOrDefaultAsync(); PublicRecitationViewModel[] recitations = poem == null ? new PublicRecitationViewModel[] { } : (await GetPoemRecitations(poemId)).Result; int loopPreventer = 0; @@ -1632,6 +1637,13 @@ namespace RMuseum.Services.Implementation } } + /// + /// older search method + /// + /// + /// + /// + /// public async Task> GetVersesByQuery(string query, int poetId, PagingParameterModel paging) { try