diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index 7400180e..6acee3b7 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -126,6 +126,29 @@ namespace RMuseum.Controllers
return Ok(res.Result);
}
+ ///
+ /// page by url
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ [Route("page")]
+ [AllowAnonymous]
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPageCompleteViewModel))]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
+ [ProducesResponseType((int)HttpStatusCode.NotFound)]
+ public async Task GetPageByUrl(string url, bool catPoems = true)
+ {
+ RServiceResult res =
+ await _ganjoorService.GetPageByUrl(url, catPoems);
+ if (!string.IsNullOrEmpty(res.ExceptionString))
+ return BadRequest(res.ExceptionString);
+ if (res.Result == null)
+ return NotFound();
+ return Ok(res.Result);
+ }
+
///
/// get poem by id
///
diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPageCompleteViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPageCompleteViewModel.cs
index 60a44ae8..12152316 100644
--- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPageCompleteViewModel.cs
+++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPageCompleteViewModel.cs
@@ -5,6 +5,10 @@
///
public class GanjoorPageCompleteViewModel
{
+ ///
+ /// id
+ ///
+ public int Id { get; set; }
///
/// Ganjoor Page Type
///
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 29fb9142..d7611be7 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -653,6 +653,14 @@
+
+
+ page by url
+
+
+
+
+
get poem by id
@@ -3699,6 +3707,11 @@
Ganjoor Page View Model
+
+
+ id
+
+
Ganjoor Page Type
@@ -4998,6 +5011,14 @@
+
+
+ get page by url
+
+
+
+
+
Get Poem By Id
@@ -5806,6 +5827,14 @@
+
+
+ get page by url
+
+
+
+
+
get poem recitations (PlainText/HtmlText are intentionally empty)
diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs
index 4708de61..061358be 100644
--- a/RMuseum/Services/IGanjoorService.cs
+++ b/RMuseum/Services/IGanjoorService.cs
@@ -50,6 +50,13 @@ namespace RMuseum.Services
///
Task> GetCatByUrl(string url, bool poems = true);
+ ///
+ /// get page by url
+ ///
+ ///
+ ///
+ ///
+ Task> GetPageByUrl(string url, bool catPoems = true);
///
/// Get Poem By Id
diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs
index 5f8b516f..ce7c55c8 100644
--- a/RMuseum/Services/Implementation/GanjoorService.cs
+++ b/RMuseum/Services/Implementation/GanjoorService.cs
@@ -271,6 +271,98 @@ namespace RMuseum.Services.Implementation
}
}
+ ///
+ /// get page by url
+ ///
+ ///
+ ///
+ ///
+ public async Task> GetPageByUrl(string url, bool catPoems = true)
+ {
+ try
+ {
+ if(url.IndexOf('?') != -1)
+ {
+ url = url.Substring(0, url.IndexOf('?'));
+ }
+
+ // /hafez/ => /hafez :
+ if (url.LastIndexOf('/') == url.Length - 1)
+ {
+ url = url.Substring(0, url.Length - 1);
+ }
+
+ var dbPage = await _context.GanjoorPages.Where(p => p.FullUrl == url).SingleOrDefaultAsync();
+ if (dbPage == null)
+ return new RServiceResult(null); //not found
+ var secondPoet = dbPage.SecondPoetId == null ? null :
+ await
+ (from poet in _context.GanjoorPoets
+ join cat in _context.GanjoorCategories.Where(c => c.ParentId == null)
+ on poet.Id equals cat.PoetId
+ where poet.Id == (int)dbPage.SecondPoetId
+ orderby poet.Name descending
+ select new GanjoorPoetViewModel()
+ {
+ Id = poet.Id,
+ Name = poet.Name,
+ FullUrl = cat.FullUrl,
+ RootCatId = cat.Id
+ }
+ )
+ .SingleAsync();
+ GanjoorPageCompleteViewModel page = new GanjoorPageCompleteViewModel()
+ {
+ Id = dbPage.Id,
+ GanjoorPageType = dbPage.GanjoorPageType,
+ Title = dbPage.Title,
+ FullTitle = dbPage.FullTitle,
+ UrlSlug = dbPage.UrlSlug,
+ FullUrl = dbPage.FullUrl,
+ HtmlText = dbPage.HtmlText,
+ SecondPoet = secondPoet
+
+ };
+ switch (page.GanjoorPageType)
+ {
+ case GanjoorPageType.PoemPage:
+ {
+ var poemRes = await GetPoemById((int)dbPage.PoemId);
+ if(!string.IsNullOrEmpty(poemRes.ExceptionString))
+ {
+ return new RServiceResult(null, poemRes.ExceptionString);
+ }
+ page.Poem = poemRes.Result;
+ }
+ break;
+ case GanjoorPageType.PoetPage:
+ {
+ var poetRes = await GetPoetById((int)dbPage.PoetId);
+ if(!string.IsNullOrEmpty(poetRes.ExceptionString))
+ {
+ return new RServiceResult(null, poetRes.ExceptionString);
+ }
+ }
+ break;
+ case GanjoorPageType.CatPage:
+ {
+ var catRes = await GetCatById((int)dbPage.CatId);
+ if(!string.IsNullOrEmpty(catRes.ExceptionString))
+ {
+ return new RServiceResult(null, catRes.ExceptionString);
+ }
+ }
+ break;
+ }
+ return new RServiceResult(page);
+
+ }
+ catch(Exception exp)
+ {
+ return new RServiceResult(null, exp.ToString());
+ }
+ }
+
///