diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index 83ca434f..7ac8feee 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -58,6 +58,28 @@ namespace RMuseum.Controllers
return Ok(res.Result);
}
+ ///
+ /// poet by url
+ ///
+ ///
+ ///
+ [HttpGet]
+ [Route("poet")]
+ [AllowAnonymous]
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
+ [ProducesResponseType((int)HttpStatusCode.NotFound)]
+ public async Task GetPoetByUrl(string url)
+ {
+ RServiceResult res =
+ await _ganjoorService.GetPoetByUrl(url);
+ if (!string.IsNullOrEmpty(res.ExceptionString))
+ return BadRequest(res.ExceptionString);
+ if (res.Result == null)
+ return NotFound();
+ return Ok(res.Result);
+ }
+
///
/// cat by id
///
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 85df5fbf..eb73f625 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -630,6 +630,13 @@
+
+
+ poet by url
+
+
+
+
cat by id
@@ -4672,11 +4679,19 @@
+
+
+ get poet by url
+
+
+
+
get cat by id
+
@@ -5442,6 +5457,13 @@
+
+
+ get poet by url
+
+
+
+
get cat by id
diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs
index f82f624b..a076cba3 100644
--- a/RMuseum/Services/IGanjoorService.cs
+++ b/RMuseum/Services/IGanjoorService.cs
@@ -27,10 +27,18 @@ namespace RMuseum.Services
///
Task> GetPoetById(int id);
+ ///
+ /// get poet by url
+ ///
+ ///
+ ///
+ Task> GetPoetByUrl(string url);
+
///
/// get cat by id
///
///
+ ///
///
Task> GetCatById(int id, bool poems = true);
diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs
index d7339313..135b889b 100644
--- a/RMuseum/Services/Implementation/GanjoorService.cs
+++ b/RMuseum/Services/Implementation/GanjoorService.cs
@@ -88,6 +88,31 @@ namespace RMuseum.Services.Implementation
}
}
+ ///
+ /// get poet by url
+ ///
+ ///
+ ///
+ public async Task> GetPoetByUrl(string url)
+ {
+ try
+ {
+ // /hafez/ => /hafez :
+ if(url.LastIndexOf('/') == url.Length - 1)
+ {
+ url = url.Substring(0, url.Length - 1);
+ }
+ var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url && c.ParentId == null).SingleOrDefaultAsync();
+ if (cat == null)
+ return new RServiceResult(null);
+ return await GetCatById(cat.Id);
+ }
+ catch (Exception exp)
+ {
+ return new RServiceResult(null, exp.ToString());
+ }
+ }
+
///
/// get cat by id
///