diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 048f8f1f..cfc318b9 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -1894,7 +1894,7 @@ namespace RMuseum.Controllers [Authorize] [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] - public async Task BookmarkArtifact(int poemId, int verseId) + public async Task BookmarkVerse(int poemId, int verseId) { Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); RServiceResult res = await _ganjoorService.BookmarkVerse(poemId, verseId, loggedOnUserId, RBookmarkType.Bookmark); @@ -1922,6 +1922,26 @@ namespace RMuseum.Controllers return Ok(); } + /// + /// switch bookmark + /// + /// + /// + /// + [HttpPost] + [Route("bookmark/switch/{poemId}/{verseId}")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task SwitchBookmark(int poemId, int verseId) + { + Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + RServiceResult res = await _ganjoorService.SwitchBookmarkVerse(poemId, verseId, loggedOnUserId, RBookmarkType.Bookmark); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(res.Result); + } + /// /// fav poem /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index a43b24a7..3fce2758 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1210,7 +1210,7 @@ - + bookmark verse @@ -1225,6 +1225,14 @@ + + + switch bookmark + + + + + fav poem @@ -8659,6 +8667,16 @@ + + + Switch Bookmark Verse + + + + + + + get user ganjoor bookmarks @@ -9736,6 +9754,16 @@ IGanjoorService implementation + + + Bookmark Verse + + + + + + + Bookmark Verse diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index d4425827..4a57e4c6 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -577,6 +577,16 @@ namespace RMuseum.Services /// Task> BookmarkVerse(int poemId, int verseId, Guid userId, RBookmarkType type); + /// + /// Switch Bookmark Verse + /// + /// + /// + /// + /// + /// + Task> SwitchBookmarkVerse(int poemId, int verseId, Guid userId, RBookmarkType type); + /// /// get user ganjoor bookmarks /// diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs index 01c5c411..e8b27acc 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Bookmarking.cs @@ -16,6 +16,36 @@ namespace RMuseum.Services.Implementation /// public partial class GanjoorService : IGanjoorService { + /// + /// Bookmark Verse + /// + /// + /// + /// + /// + /// + public async Task> SwitchBookmarkVerse(int poemId, int verseId, Guid userId, RBookmarkType type) + { + var bookmark = await _context.GanjoorUserBookmarks.Where(b => b.UserId == userId && b.PoemId == poemId && b.VerseId == verseId && b.RBookmarkType == type).SingleOrDefaultAsync(); + if (bookmark != null) + { + var res = await DeleteGanjoorBookmark(bookmark.Id, userId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return new RServiceResult(null, res.ExceptionString); + bookmark = null; + + } + else + { + var res = await BookmarkVerse(poemId, verseId, userId, type); + if(!string.IsNullOrEmpty(res.ExceptionString)) + return res; + bookmark = res.Result; + } + return new RServiceResult(bookmark); + } + + /// /// Bookmark Verse ///