diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs
index 5beb0d97..d582cb4f 100644
--- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs
+++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs
@@ -22,6 +22,16 @@ namespace RMuseum.Models.Ganjoor.ViewModels
///
public string UrlSlug { get; set; }
+ ///
+ /// Next Category without Ancestors/Children/Poems info
+ ///
+ public GanjoorCatViewModel Next { get; set; }
+
+ ///
+ /// Previous Category without Ancestors/Children/Poems info
+ ///
+ public GanjoorCatViewModel Previous { get; set; }
+
///
/// ancestors
///
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index d8716524..ff913e34 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -3460,6 +3460,16 @@
url => slug
+
+
+ Next Category without Ancestors/Children/Poems info
+
+
+
+
+ Previous Category without Ancestors/Children/Poems info
+
+
ancestors
diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs
index 73d8c06f..db0de115 100644
--- a/RMuseum/Services/Implementation/GanjoorService.cs
+++ b/RMuseum/Services/Implementation/GanjoorService.cs
@@ -117,11 +117,54 @@ namespace RMuseum.Services.Implementation
parent = await _context.GanjoorCategories.Where(c => c.Id == parent.ParentId).FirstOrDefaultAsync();
}
+
+ int nextCatId =
+ await _context.GanjoorCategories.Where(c => c.PoetId == cat.PoetId && c.ParentId == cat.ParentId && c.Id > id).AnyAsync() ?
+ await _context.GanjoorCategories.Where(c => c.PoetId == cat.PoetId && c.ParentId == cat.ParentId && c.Id > id).MinAsync(c => c.Id)
+ :
+ 0;
+ var nextCat = nextCatId == 0 ? null : await _context
+ .GanjoorCategories
+ .Where(c => c.Id == nextCatId)
+ .Select
+ (
+ c =>
+ new GanjoorCatViewModel()
+ {
+ Id = c.Id,
+ Title = c.Title,
+ UrlSlug = c.UrlSlug
+ //other fields null
+ }
+ ).SingleOrDefaultAsync();
+
+ int preCatId =
+ await _context.GanjoorCategories.Where(c => c.PoetId == cat.PoetId && c.ParentId == cat.ParentId && c.Id < id).AnyAsync() ?
+ await _context.GanjoorCategories.Where(c => c.PoetId == cat.PoetId && c.ParentId == cat.ParentId && c.Id < id).MaxAsync(c => c.Id)
+ :
+ 0;
+ var preCat = preCatId == 0 ? null : await _context
+ .GanjoorCategories
+ .Where(c => c.Id == preCatId)
+ .Select
+ (
+ c =>
+ new GanjoorCatViewModel()
+ {
+ Id = c.Id,
+ Title = c.Title,
+ UrlSlug = c.UrlSlug
+ //other fields null
+ }
+ ).SingleOrDefaultAsync();
+
GanjoorCatViewModel catViewModel = new GanjoorCatViewModel()
{
Id = cat.Id,
Title = cat.Title,
UrlSlug = cat.UrlSlug,
+ Next = nextCat,
+ Previous = preCat,
Ancestors = ancetors,
Children = await _context.GanjoorCategories.Where(c => c.ParentId == cat.Id).OrderBy(cat => cat.Id).Select
(
@@ -310,10 +353,17 @@ namespace RMuseum.Services.Implementation
GanjoorPoemSummaryViewModel next = null;
if(navigation)
{
- int? nextId = await _context.GanjoorPoems
+ int nextId =
+ await _context.GanjoorPoems
.Where(p => p.CatId == poem.CatId && p.Id > poem.Id)
- .MinAsync(p => p.Id);
- if(nextId != null)
+ .AnyAsync()
+ ?
+ await _context.GanjoorPoems
+ .Where(p => p.CatId == poem.CatId && p.Id > poem.Id)
+ .MinAsync(p => p.Id)
+ :
+ 0;
+ if(nextId != 0)
{
next = await _context.GanjoorPoems.Where(p => p.Id == nextId).Select
(
@@ -333,10 +383,17 @@ namespace RMuseum.Services.Implementation
GanjoorPoemSummaryViewModel previous = null;
if (navigation)
{
- int? preId = await _context.GanjoorPoems
+ int preId =
+ await _context.GanjoorPoems
.Where(p => p.CatId == poem.CatId && p.Id < poem.Id)
- .MaxAsync(p => p.Id);
- if (preId != null)
+ .AnyAsync()
+ ?
+ await _context.GanjoorPoems
+ .Where(p => p.CatId == poem.CatId && p.Id < poem.Id)
+ .MaxAsync(p => p.Id)
+ :
+ 0;
+ if (preId != 0)
{
previous = await _context.GanjoorPoems.Where(p => p.Id == preId).Select
(