diff --git a/GanjooRazor/Pages/Index.cshtml.cs b/GanjooRazor/Pages/Index.cshtml.cs
index 05d1fadb..f9490882 100644
--- a/GanjooRazor/Pages/Index.cshtml.cs
+++ b/GanjooRazor/Pages/Index.cshtml.cs
@@ -48,7 +48,7 @@ namespace GanjooRazor.Pages
///
///
///
- public IndexModel(IConfiguration configuration,
+ public IndexModel(IConfiguration configuration,
HttpClient httpClient,
IMemoryCache memoryCache
)
@@ -182,7 +182,7 @@ namespace GanjooRazor.Pages
return await OnPostComment(replyCommentText, refPoemId, refCommentId, -1);
}
-
+
///
/// comment
@@ -228,7 +228,7 @@ namespace GanjooRazor.Pages
Error = "",
InReplyTo = inReplytoId == 0 ? null : new GanjoorCommentSummaryViewModel(),
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"])
- }
+ }
}
};
}
@@ -280,7 +280,7 @@ namespace GanjooRazor.Pages
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
- var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/comment?id={id}");
+ var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/comment?id={id}");
if (response.StatusCode != HttpStatusCode.OK)
{
@@ -417,7 +417,7 @@ namespace GanjooRazor.Pages
private void _markMyReplies(GanjoorCommentSummaryViewModel parent, Guid userId)
{
- foreach(var reply in parent.Replies)
+ foreach (var reply in parent.Replies)
{
reply.MyComment = reply.UserId == userId;
_markMyReplies(reply, userId);
@@ -504,7 +504,7 @@ namespace GanjooRazor.Pages
return Redirect(pageUrl);
}
- if(Request.Path.ToString().IndexOf("index.php") != -1)
+ if (Request.Path.ToString().IndexOf("index.php") != -1)
{
return Redirect($"{Request.Path.ToString().Replace("index.php", "search")}{Request.QueryString}");
}
@@ -618,7 +618,7 @@ namespace GanjooRazor.Pages
ViewData["Title"] = $"گنجور » {GanjoorPage.FullTitle}";
- switch(GanjoorPage.UrlSlug)
+ switch (GanjoorPage.UrlSlug)
{
case "hashieha":
await _GenerateHashiehaHtmlText();
@@ -633,21 +633,21 @@ namespace GanjooRazor.Pages
}
breadCrumbList.AddItem(GanjoorPage.Title, GanjoorPage.FullUrl, "https://i.ganjoor.net/cat.png");
}
-
+
ViewData["BrearCrumpList"] = breadCrumbList.ToString();
-
+
return Page();
}
public async Task OnGetBNumPartialAsync(int poemId, int coupletIndex)
{
- var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}/comments?coupletIndex={coupletIndex}");
- response.EnsureSuccessStatusCode();
+ var responseCoupletComments = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{poemId}/comments?coupletIndex={coupletIndex}");
+ responseCoupletComments.EnsureSuccessStatusCode();
- var comments = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>();
+ var comments = JArray.Parse(await responseCoupletComments.Content.ReadAsStringAsync()).ToObject>();
bool isBookmarked = false;
@@ -655,14 +655,25 @@ namespace GanjooRazor.Pages
{
if (Guid.TryParse(Request.Cookies["UserId"], out Guid userId))
if (userId != Guid.Empty)
+ {
foreach (GanjoorCommentSummaryViewModel comment in comments)
{
comment.MyComment = comment.UserId == userId;
_markMyReplies(comment, userId);
}
- }
-
+ using (HttpClient secureClient = new HttpClient())
+ {
+ if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
+ {
+ HttpResponseMessage responseIsBookmarked = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/bookmark/{poemId}/{coupletIndex}");
+ responseIsBookmarked.EnsureSuccessStatusCode();
+
+ isBookmarked = JsonConvert.DeserializeObject(await responseIsBookmarked.Content.ReadAsStringAsync());
+ }
+ }
+ }
+ }
return new PartialViewResult()
{
@@ -681,20 +692,20 @@ namespace GanjooRazor.Pages
};
}
- public async Task OnPostSwitchBookmarkAsync(int poemId, int vOrder)
+ public async Task OnPostSwitchBookmarkAsync(int poemId, int coupletIndex)
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.PostAsync(
- $"{APIRoot.Url}/api/ganjoor/bookmark/switch/{poemId}/{vOrder}", null);
+ $"{APIRoot.Url}/api/ganjoor/bookmark/switch/{poemId}/{coupletIndex}", null);
if (!response.IsSuccessStatusCode)
{
return new BadRequestObjectResult(JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()));
}
- var res = await response.Content.ReadAsStringAsync();
- return new OkObjectResult(res != null);
+ var res = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
+ return new OkObjectResult(res);
}
else
{
diff --git a/GanjooRazor/wwwroot/js/bj.js b/GanjooRazor/wwwroot/js/bj.js
index 3ed82eda..0827f7ce 100644
--- a/GanjooRazor/wwwroot/js/bj.js
+++ b/GanjooRazor/wwwroot/js/bj.js
@@ -402,7 +402,6 @@ function editCouplet(poemId, coupletIndex) {
}
function switchBookmark(poemId, coupletIndex) {
- var vIndex = getVerseIndexFromCoupleIndex(coupletIndex);
var iconElementId = 'bookmark-icon-' + String(coupletIndex);
document.getElementById(iconElementId).innerHTML = 'star_half';
var url = '/?handler=SwitchBookmark';
@@ -412,7 +411,7 @@ function switchBookmark(poemId, coupletIndex) {
url: url,
data: {
poemId: poemId,
- vOrder: (vIndex + 1)
+ coupletIndex: coupletIndex
},
error: function (err) {
alert(err)
diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index 1842eb93..d0dd1122 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -1893,7 +1893,7 @@ namespace RMuseum.Controllers
[HttpPost]
[Route("bookmark/switch/{poemId}/{coupletIndex}")]
[Authorize]
- [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorUserBookmark))]
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task SwitchCoupletBookmark(int poemId, int coupletIndex)
{
@@ -1901,7 +1901,7 @@ namespace RMuseum.Controllers
RServiceResult res = await _ganjoorService.SwitchCoupletBookmark(loggedOnUserId, poemId, coupletIndex);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
- return Ok(res.Result);
+ return Ok(res.Result != null);
}