diff --git a/GanjooRazor/Areas/Admin/Pages/Banners.cshtml b/GanjooRazor/Areas/Admin/Pages/Banners.cshtml new file mode 100644 index 00000000..57159421 --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/Banners.cshtml @@ -0,0 +1,55 @@ +@page +@model GanjooRazor.Areas.Admin.Pages.BannersModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_AdminLayout"; + ViewData["Title"] = "آگاهی‌ها"; +} + +

@ViewData["Title"]

+ + +

@Model.LastMessage

+ +
+ + + + +
+ +@if (Model.Banners != null) +{ + + + @foreach (var banner in Model.Banners) + { + + + + + @if (banner.Active) + { + + } + else + { + + } + + + } +
متن جایگزین: نشانی مقصد: @banner.AlternateTextفعال فعال + ✎ + 🗑 +
+ +
+
+ + + + +
+
+} diff --git a/GanjooRazor/Areas/Admin/Pages/Banners.cshtml.cs b/GanjooRazor/Areas/Admin/Pages/Banners.cshtml.cs new file mode 100644 index 00000000..ed199da4 --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/Banners.cshtml.cs @@ -0,0 +1,157 @@ +using GanjooRazor.Models; +using GanjooRazor.Utils; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using RMuseum.Models.Ganjoor.ViewModels; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace GanjooRazor.Areas.Admin.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class BannersModel : PageModel + { + /// + /// image + /// + [BindProperty] + public BannerUploadModel Upload { get; set; } + + /// + /// last message + /// + public string LastMessage { get; set; } + + + /// + /// banners + /// + public GanjoorSiteBannerViewModel[] Banners { get; set; } + + public async Task OnGetAsync() + { + LastMessage = ""; + + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/site/banners"); + if (!response.IsSuccessStatusCode) + { + LastMessage = await response.Content.ReadAsStringAsync(); + } + + response.EnsureSuccessStatusCode(); + + Banners = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + + } + else + { + LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + + return Page(); + } + + /// + /// edit + /// + /// + public async Task OnPutEditAsync(int id, string alt, string url, bool active) + { + LastMessage = ""; + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + GanjoorSiteBannerModifyViewModel model = new GanjoorSiteBannerModifyViewModel() + { + AlternateText = alt, + TargetUrl = url, + Active = active + }; + HttpResponseMessage response = await secureClient.PutAsync($"{APIRoot.Url}/api/ganjoor/site/banner/{id}", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")); + if (!response.IsSuccessStatusCode) + { + LastMessage = await response.Content.ReadAsStringAsync(); + } + + + } + else + { + LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + + return new JsonResult(true); + } + + public async Task OnDeleteAsync(int id) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/site/banner?id={id}"); + + if (response.StatusCode != HttpStatusCode.OK) + { + return Redirect($"/login?redirect={Request.Path}&error={await response.Content.ReadAsStringAsync()}"); + } + + } + } + return new JsonResult(true); + } + + public async Task OnPostAsync(BannerUploadModel Upload) + { + LastMessage = ""; + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + MultipartFormDataContent form = new MultipartFormDataContent(); + + using (MemoryStream stream = new MemoryStream()) + { + + form.Add(new StringContent(Upload.Alt), "alt"); + form.Add(new StringContent(Upload.Url), "url"); + + await Upload.Image.CopyToAsync(stream); + var fileContent = stream.ToArray(); + form.Add(new ByteArrayContent(fileContent, 0, fileContent.Length), Upload.Image.FileName, Upload.Image.FileName); + + HttpResponseMessage response = await secureClient.PostAsync($"{APIRoot.Url}/api/ganjoor/site/banner", form); + if (!response.IsSuccessStatusCode) + { + LastMessage = await response.Content.ReadAsStringAsync(); + } + + } + + + } + else + { + LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + + + return Page(); + } + } +} diff --git a/GanjooRazor/Areas/Admin/Pages/ModifyPage.cshtml b/GanjooRazor/Areas/Admin/Pages/ModifyPage.cshtml new file mode 100644 index 00000000..9063070a --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/ModifyPage.cshtml @@ -0,0 +1,119 @@ +@page +@model GanjooRazor.Areas.Admin.Pages.ModifyPageModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_AdminLayout"; + ViewData["Title"] = "ویرایش"; +} + +

@ViewData["Title"]

+ +

@Model.LastMessage

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ شناسهٔ صفحه: + + @Request.Query["id"] +
+ عنوان: + + +
+ نامک: + + +
+ متن: + + +
+ منبع (شعر): + + + + + + + + +
نام:
نشانی:
+ +
+ دسته‌بندی کهن (شعر): + + + + + + + + +
نام:
نشانی:
+ +
+ وزن (شعر): + + + + @if(Model.Rhythms != null) + @foreach(var rythm in Model.Rhythms) + { + + } + + +
+ حروف قافیه (شعر): + + + +
+ توضیح این ویرایش: + + + +
+ +
+
diff --git a/GanjooRazor/Areas/Admin/Pages/ModifyPage.cshtml.cs b/GanjooRazor/Areas/Admin/Pages/ModifyPage.cshtml.cs new file mode 100644 index 00000000..3a1280e8 --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/ModifyPage.cshtml.cs @@ -0,0 +1,127 @@ +using GanjooRazor.Utils; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RMuseum.Models.Ganjoor; +using RMuseum.Models.Ganjoor.ViewModels; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace GanjooRazor.Areas.Admin.Pages +{ + public class ModifyPageModel : PageModel + { + /// + /// HttpClient instance + /// + private readonly HttpClient _httpClient; + + /// + /// constructor + /// + /// + public ModifyPageModel(HttpClient httpClient) + { + _httpClient = httpClient; + } + + /// + /// Corresponding Ganojoor Page + /// + /// + /// api model + /// + [BindProperty] + public GanjoorModifyPageViewModel ModifyModel { get; set; } + + /// + /// rythm + /// + public GanjoorMetre[] Rhythms { get; set; } + + /// + /// last message + /// + public string LastMessage { get; set; } + + public async Task OnGetAsync() + { + LastMessage = Request.Query["edit"] == "true" ? "ویرایش انجام شد." : ""; + if (string.IsNullOrEmpty(Request.Query["id"])) + { + return StatusCode(StatusCodes.Status500InternalServerError, "شناسهٔ صفحه مشخص نیست."); + } + var rhythmResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/rhythms"); + + rhythmResponse.EnsureSuccessStatusCode(); + + Rhythms = JsonConvert.DeserializeObject(await rhythmResponse.Content.ReadAsStringAsync()); + + + var pageUrlResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={Request.Query["id"]}"); + + if (!pageUrlResponse.IsSuccessStatusCode) + { + return StatusCode(StatusCodes.Status500InternalServerError, await pageUrlResponse.Content.ReadAsStringAsync()); + } + + pageUrlResponse.EnsureSuccessStatusCode(); + + var pageUrl = JsonConvert.DeserializeObject(await pageUrlResponse.Content.ReadAsStringAsync()); + + var pageQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={pageUrl}"); + if (!pageQuery.IsSuccessStatusCode) + { + return StatusCode(StatusCodes.Status500InternalServerError, await pageQuery.Content.ReadAsStringAsync()); + } + GanjoorPageCompleteViewModel page = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject(); + + ModifyModel = new GanjoorModifyPageViewModel() + { + Title = page.Title, + UrlSlug = page.UrlSlug, + HtmlText = page.HtmlText, + Note = "", + SourceName = page.Poem == null ? null : page.Poem.SourceName, + SourceUrlSlug = page.Poem == null ? null : page.Poem.SourceUrlSlug, + OldTag = page.Poem == null ? null : page.Poem.OldTag, + OldTagPageUrl = page.Poem == null ? null : page.Poem.OldTagPageUrl, + RhymeLetters = page.Poem == null ? null : page.Poem.RhymeLetters, + Rhythm = page.Poem == null ? null : page.Poem.GanjoorMetre == null ? null : page.Poem.GanjoorMetre.Rhythm + }; + + return Page(); + } + + public async Task OnPostAsync() + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var putResponse = await secureClient.PutAsync($"{APIRoot.Url}/api/ganjoor/page/{Request.Query["id"]}", new StringContent(JsonConvert.SerializeObject(ModifyModel), Encoding.UTF8, "application/json")); + if (!putResponse.IsSuccessStatusCode) + { + LastMessage = await putResponse.Content.ReadAsStringAsync(); + } + else + { + return Redirect($"/Admin/ModifyPage?id={Request.Query["id"]}&edit=true"); + } + } + else + { + LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + + + return Page(); + + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/AddSong.cshtml b/GanjooRazor/Areas/User/Pages/AddSong.cshtml new file mode 100644 index 00000000..d341186a --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/AddSong.cshtml @@ -0,0 +1,100 @@ +@page +@model GanjooRazor.Areas.User.Pages.AddSongModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_Layout"; + ViewData["Title"] = "آهنگ مرتبط از منابع دلخواه"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); +} + +

@ViewData["Title"]

+ +@if (Model.LastError != "") +{ +

@Model.LastError

+} + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ شناسهٔ شعر: + + +
+ خواننده: + +
+
+ نشانی خواننده: + + +
+ +
+ آلبوم: + +
+
+ نشانی آلبوم: + + +
+ آهنگ: + + +
+ نشانی آهنگ: + + +
+ توضیح: + +
+
+ +
+ +
\ No newline at end of file diff --git a/GanjooRazor/Areas/User/Pages/AddSong.cshtml.cs b/GanjooRazor/Areas/User/Pages/AddSong.cshtml.cs new file mode 100644 index 00000000..63205c48 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/AddSong.cshtml.cs @@ -0,0 +1,77 @@ +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using GanjooRazor.Utils; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using RMuseum.Models.Ganjoor.ViewModels; + +namespace GanjooRazor.Areas.User.Pages +{ + public class AddSongModel : PageModel + { + /// + /// Last Error + /// + public string LastError { get; set; } + + /// + /// api model + /// + [BindProperty] + public PoemMusicTrackViewModel PoemMusicTrackViewModel { get; set; } + + /// + /// poem id + /// + public int PoemId { get; set; } + + public void OnGet() + { + PoemMusicTrackViewModel = new PoemMusicTrackViewModel() + { + TrackType = RMuseum.Models.Ganjoor.PoemMusicTrackType.BeepTunesOrKhosousi, + PoemId = 0, + ArtistName = "محمدرضا شجریان", + ArtistUrl = "http://beeptunes.com/artist/3403349", + AlbumName = "اجراهای خصوصی", + AlbumUrl = "http://khosousi.com", + TrackName = "", + TrackUrl = "", + Approved = false, + Rejected = false, + BrokenLink = false, + Description = "" + }; + } + + public async Task OnPostAsync() + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var putResponse = await secureClient.PostAsync($"{APIRoot.Url}/api/ganjoor/song/add", new StringContent(JsonConvert.SerializeObject(PoemMusicTrackViewModel), Encoding.UTF8, "application/json")); + if (!putResponse.IsSuccessStatusCode) + { + LastError = await putResponse.Content.ReadAsStringAsync(); + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + + + if (!string.IsNullOrEmpty(LastError)) + { + return Page(); + } + + return Redirect("/User/AddSong"); + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/Index.cshtml b/GanjooRazor/Areas/User/Pages/Index.cshtml new file mode 100644 index 00000000..719ad480 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Index.cshtml @@ -0,0 +1,128 @@ +@page +@model GanjooRazor.Areas.Panel.Pages.IndexModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_Layout"; + ViewData["Title"] = "پیشخان کاربر"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); +} +

@ViewData["Title"]

+@if (Model.LastError != "") +{ +

@Model.LastError

+} +else +{ +
+ + + + + + + + + + + + + + + + + + + + + + +
+

تغییر گذرواژه

+
+ گذرواژهٔ کنونی: + +
+
+ گذرواژهٔ جدید: + +
+
+ تکرار گذرواژهٔ جدید: + +
+
+ @Model.PasswordChanged + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

تغییر مشخصات

+
+ نام: + +
+
+ نام خانوادگی: + +
+
+ نام مستعار (نمایش در حاشیه‌ها): + +
+
+ وبگاه: + + +
+ دربارهٔ من: + + +
+ + + + + + + + + +
+ نمایهٔ عمومی من +
+
+} \ No newline at end of file diff --git a/GanjooRazor/Areas/User/Pages/Index.cshtml.cs b/GanjooRazor/Areas/User/Pages/Index.cshtml.cs new file mode 100644 index 00000000..e240adb8 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Index.cshtml.cs @@ -0,0 +1,165 @@ +using GanjooRazor.Models.User; +using GanjooRazor.Utils; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using RSecurityBackend.Models.Auth.ViewModels; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace GanjooRazor.Areas.Panel.Pages +{ + public class IndexModel : PageModel + { + /// + /// api model + /// + + [BindProperty] + public RegisterRAppUser UserInfo { get; set; } + + [BindProperty] + public ChangePasswordModel ChangePasswordModel { get; set; } + + /// + /// Last Error + /// + public string LastError { get; set; } + + /// + /// password changed + /// + public string PasswordChanged { get; set; } + + /// + /// get + /// + public async Task OnGetAsync() + { + LastError = ""; + PasswordChanged = ""; + await _PreparePage(); + } + + private async Task _PreparePage() + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var userInfoResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/users/{Request.Cookies["UserId"]}"); + if (userInfoResponse.IsSuccessStatusCode) + { + PublicRAppUser userInfo = JsonConvert.DeserializeObject(await userInfoResponse.Content.ReadAsStringAsync()); + + UserInfo = new RegisterRAppUser() + { + Id = userInfo.Id, + Username = userInfo.Username, + FirstName = userInfo.FirstName, + SureName = userInfo.SureName, + NickName = userInfo.NickName, + PhoneNumber = userInfo.PhoneNumber, + Email = userInfo.Email, + Website = userInfo.Website, + Bio = userInfo.Bio, + RImageId = userInfo.RImageId, + Status = userInfo.Status, + IsAdmin = false, + Password = "" + }; + } + else + { + LastError = await userInfoResponse.Content.ReadAsStringAsync(); + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + } + } + + public async Task OnPostSetMyInfoAsync(RegisterRAppUser UserInfo) + { + LastError = ""; + PasswordChanged = ""; + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var isAdminResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/users/isadmin?userId={Request.Cookies["UserId"]}"); + if (isAdminResponse.IsSuccessStatusCode) + { + UserInfo.IsAdmin = JsonConvert.DeserializeObject(await isAdminResponse.Content.ReadAsStringAsync()); + + var putResponse = await secureClient.PutAsync($"{APIRoot.Url}/api/users/{Request.Cookies["UserId"]}", new StringContent(JsonConvert.SerializeObject(UserInfo), Encoding.UTF8, "application/json")); + + if(!putResponse.IsSuccessStatusCode) + { + LastError = await putResponse.Content.ReadAsStringAsync(); + } + } + else + { + LastError = await isAdminResponse.Content.ReadAsStringAsync(); + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + } + await _PreparePage(); + return Page(); + } + + public async Task OnPostSetMyPassAsync(ChangePasswordModel ChangePasswordModel) + { + LastError = ""; + PasswordChanged = ""; + if (ChangePasswordModel.NewPasswordRepeat != ChangePasswordModel.NewPassword) + { + LastError = "گذرواژهٔ جدید با تکرار آن همسان نیست."; + return Page(); + } + if(ChangePasswordModel.NewPassword == ChangePasswordModel.OldPassword) + { + LastError = "گذرواژهٔ جدید با گذرواژهٔ کنونی یکسان است."; + return Page(); + } + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var changePassResp = await secureClient.PostAsync($"{APIRoot.Url}/api/users/setmypassword", + new StringContent(JsonConvert.SerializeObject + ( + new SetPasswordModel() + { + OldPassword = ChangePasswordModel.OldPassword, + NewPassword = ChangePasswordModel.NewPassword + } + ), + Encoding.UTF8, "application/json")); + if (!changePassResp.IsSuccessStatusCode) + { + LastError = await changePassResp.Content.ReadAsStringAsync(); + } + else + { + PasswordChanged = "گذرواژهٔ شما به درستی تغییر کرد."; + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + } + await _PreparePage(); + return Page(); + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/MyComments.cshtml b/GanjooRazor/Areas/User/Pages/MyComments.cshtml new file mode 100644 index 00000000..035e4086 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/MyComments.cshtml @@ -0,0 +1,91 @@ +@page +@model GanjooRazor.Areas.User.Pages.MyCommentsModel +@using DNTPersianUtils.Core +@{ + Layout = "_Layout"; + ViewData["Title"] = "حاشیه‌های من"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); + string color = "gray"; +} +

@ViewData["Title"]

+@if (Model.LastError != "") +{ +

@Model.LastError

+} +else +{ +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+ + @foreach (var comment in Model.Comments) + { + if (color == "gray") + color = "white"; + else + color = "gray"; + +
+
+
+ @Html.Raw(comment.HtmlComment) +
+

+ @comment.AuthorName در @comment.CommentDate.ToFriendlyPersianDateTextify() دربارهٔ @comment.Poem.Title +

+
+

+ 🗑 + ✎ +

+
+ + +
+ } + +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+ + +} \ No newline at end of file diff --git a/GanjooRazor/Areas/User/Pages/MyComments.cshtml.cs b/GanjooRazor/Areas/User/Pages/MyComments.cshtml.cs new file mode 100644 index 00000000..fcc7de72 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/MyComments.cshtml.cs @@ -0,0 +1,174 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using DNTPersianUtils.Core; +using GanjooRazor.Utils; +using GSpotifyProxy.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; + +namespace GanjooRazor.Areas.User.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class MyCommentsModel : PageModel + { + // + /// Last Error + /// + public string LastError { get; set; } + + /// + /// comments + /// + public List Comments { get; set; } + + /// + /// pagination links + /// + public List PaginationLinks { get; set; } + + + public async Task OnGetAsync() + { + LastError = ""; + using (HttpClient secureClient = new HttpClient()) + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + { + int pageNumber = 1; + if (!string.IsNullOrEmpty(Request.Query["page"])) + { + pageNumber = int.Parse(Request.Query["page"]); + } + var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/comments/mine?PageNumber={pageNumber}&PageSize=20"); + if (!response.IsSuccessStatusCode) + { + LastError = await response.Content.ReadAsStringAsync(); + return Page(); + } + response.EnsureSuccessStatusCode(); + + Comments = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>(); + + string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject(paginnationMetadata); + PaginationLinks = new List(); + if (paginationMetadata.totalPages > 1) + { + if (paginationMetadata.currentPage > 3) + { + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ اول", + Url = "/User/MyComments/?page=1" + } + ); + } + for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++) + { + if (i >= 1 && i <= paginationMetadata.totalPages) + { + if (i == paginationMetadata.currentPage) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + } + ); + } + else + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + Url = $"/User/MyComments/?page={i}" + } + ); + } + } + } + if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2)) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "... ", + } + ); + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ آخر", + Url = $"/User/MyComments/?page={paginationMetadata.totalPages}" + } + ); + } + } + } + + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + return Page(); + } + + + public async Task OnDeleteMyComment(int id) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/comment?id={id}"); + + if (response.StatusCode != HttpStatusCode.OK) + { + return Redirect($"/login?redirect={Request.Path}&error={await response.Content.ReadAsStringAsync()}"); + } + + } + } + return new JsonResult(true); + } + + public async Task OnPutMyComment(int id, string comment) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var response = await secureClient.PutAsync($"{APIRoot.Url}/api/ganjoor/comment/{id}", new StringContent(JsonConvert.SerializeObject(comment), Encoding.UTF8, "application/json")); + if (response.StatusCode != HttpStatusCode.OK) + { + return Redirect($"/login?redirect={Request.Path}&error={await response.Content.ReadAsStringAsync()}"); + } + } + } + return new JsonResult(true); + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/Notifications.cshtml b/GanjooRazor/Areas/User/Pages/Notifications.cshtml new file mode 100644 index 00000000..4d7bc54b --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Notifications.cshtml @@ -0,0 +1,71 @@ +@page +@model GanjooRazor.Areas.User.Pages.NotificationsModel +@using DNTPersianUtils.Core +@{ + Layout = "_Layout"; + ViewData["Title"] = "اعلان‌های من"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); + string color = "gray"; +} +

@ViewData["Title"]

+@if (Model.LastError != "") +{ +

@Model.LastError

+} +else +{ +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+ + @foreach (var notification in Model.Notifications) + { + if (color == "gray") + color = "white"; + else + color = "gray"; + +
+
+

+ @notification.Subject در @notification.DateTime.ToFriendlyPersianDateTextify() +

+
+ @Html.Raw(notification.HtmlText) +
+
+

+ 🗑 +

+
+ + +
+ } + +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+ + +} diff --git a/GanjooRazor/Areas/User/Pages/Notifications.cshtml.cs b/GanjooRazor/Areas/User/Pages/Notifications.cshtml.cs new file mode 100644 index 00000000..a4613299 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/Notifications.cshtml.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using DNTPersianUtils.Core; +using GanjooRazor.Utils; +using GSpotifyProxy.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; +using RSecurityBackend.Models.Notification.ViewModels; + +namespace GanjooRazor.Areas.User.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class NotificationsModel : PageModel + { + // + /// Last Error + /// + public string LastError { get; set; } + + /// + /// pagination links + /// + public List PaginationLinks { get; set; } + + /// + /// Notifications + /// + public List Notifications { get; set; } + + public async Task OnGetAsync() + { + LastError = ""; + using (HttpClient secureClient = new HttpClient()) + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + { + int pageNumber = 1; + if (!string.IsNullOrEmpty(Request.Query["page"])) + { + pageNumber = int.Parse(Request.Query["page"]); + } + var response = await secureClient.GetAsync($"{APIRoot.Url}/api/notifications/paginated?PageNumber={pageNumber}&PageSize=20"); + if (!response.IsSuccessStatusCode) + { + LastError = await response.Content.ReadAsStringAsync(); + return Page(); + } + response.EnsureSuccessStatusCode(); + + Notifications = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>(); + + string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject(paginnationMetadata); + PaginationLinks = new List(); + if (paginationMetadata.totalPages > 1) + { + if (paginationMetadata.currentPage > 3) + { + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ اول", + Url = "/User/Notifications/?page=1" + } + ); + } + for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++) + { + if (i >= 1 && i <= paginationMetadata.totalPages) + { + if (i == paginationMetadata.currentPage) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + } + ); + } + else + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + Url = $"/User/Notifications/?page={i}" + } + ); + } + } + } + if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2)) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "... ", + } + ); + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ آخر", + Url = $"/User/Notifications/?page={paginationMetadata.totalPages}" + } + ); + } + } + } + + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + return Page(); + } + + public async Task OnDeleteNotification(Guid id) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/notifications/{id}"); + + if (response.StatusCode != HttpStatusCode.OK) + { + return Redirect($"/login?redirect={Request.Path}&error={await response.Content.ReadAsStringAsync()}"); + } + + } + } + return new JsonResult(true); + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/ReportedComments.cshtml b/GanjooRazor/Areas/User/Pages/ReportedComments.cshtml new file mode 100644 index 00000000..988c5951 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/ReportedComments.cshtml @@ -0,0 +1,75 @@ +@page +@model GanjooRazor.Areas.User.Pages.ReportedCommentsModel +@using DNTPersianUtils.Core +@{ + Layout = "_Layout"; + ViewData["Title"] = "حاشیه‌های گزارش شده"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); + string color = "gray"; +} +

@ViewData["Title"]

+@if (Model.LastError != "") +{ +

@Model.LastError

+} +else +{ +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+ + @foreach (var report in Model.Reports) + { + if (color == "gray") + color = "white"; + else + color = "gray"; + +
+

+ @report.ReasonCode +

+
+

+ @report.ReasonText +

+
+
+ @Html.Raw(report.Comment.HtmlComment) +

+ @report.Comment.AuthorName در @report.Comment.CommentDate.ToFriendlyPersianDateTextify() دربارهٔ @report.Comment.Poem.Title +

+
+ ✓ درست می‌گوید +     + گزارش نابجا ❌ +
+ + +
+ } + +

+ @foreach (var paginationLink in Model.PaginationLinks) + { + if (!string.IsNullOrEmpty(paginationLink.Url)) + { + @paginationLink.Name + } + else + { + @paginationLink.Name + } + } +

+} \ No newline at end of file diff --git a/GanjooRazor/Areas/User/Pages/ReportedComments.cshtml.cs b/GanjooRazor/Areas/User/Pages/ReportedComments.cshtml.cs new file mode 100644 index 00000000..f72d565f --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/ReportedComments.cshtml.cs @@ -0,0 +1,189 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using DNTPersianUtils.Core; +using GanjooRazor.Utils; +using GSpotifyProxy.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; +using System.Text; + +namespace GanjooRazor.Areas.User.Pages +{ + [IgnoreAntiforgeryToken(Order = 1001)] + public class ReportedCommentsModel : PageModel + { + /// + /// Last Error + /// + public string LastError { get; set; } + + + /// + /// comments + /// + public List Reports { get; set; } + + /// + /// pagination links + /// + public List PaginationLinks { get; set; } + + + public async Task OnGetAsync() + { + LastError = ""; + using (HttpClient secureClient = new HttpClient()) + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + { + int pageNumber = 1; + if (!string.IsNullOrEmpty(Request.Query["page"])) + { + pageNumber = int.Parse(Request.Query["page"]); + } + var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/comments/reported?PageNumber={pageNumber}&PageSize=20"); + if (!response.IsSuccessStatusCode) + { + LastError = await response.Content.ReadAsStringAsync(); + return Page(); + } + response.EnsureSuccessStatusCode(); + + Reports = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>(); + + string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject(paginnationMetadata); + PaginationLinks = new List(); + if (paginationMetadata.totalPages > 1) + { + if (paginationMetadata.currentPage > 3) + { + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ اول", + Url = "/User/ReportedComments/?page=1" + } + ); + } + for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++) + { + if (i >= 1 && i <= paginationMetadata.totalPages) + { + if (i == paginationMetadata.currentPage) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + } + ); + } + else + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = i.ToPersianNumbers(), + Url = $"/User/ReportedComments/?page={i}" + } + ); + } + } + } + if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2)) + { + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "... ", + } + ); + + PaginationLinks.Add + ( + new NameIdUrlImage() + { + Name = "صفحهٔ آخر", + Url = $"/User/ReportedComments/?page={paginationMetadata.totalPages}" + } + ); + } + } + } + + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + return Page(); + } + + public async Task OnPostModerateComment(int id, string reasonCode, string reasonText) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + string reason; + switch(reasonCode) + { + case "offensive": + reason = "توهین آمیز است. " + reasonText; + break; + case "bogus": + reason = "نامفهوم است. " + reasonText; + break; + default: + reason = reasonText; + break; + } + var response = await secureClient.PostAsync($"{APIRoot.Url}/api/ganjoor/comment/moderate/{id}", new StringContent(JsonConvert.SerializeObject(reason), Encoding.UTF8, "application/json")); + + if (response.StatusCode != HttpStatusCode.OK) + { + return Redirect($"/login?redirect={Request.Path}&error={await response.Content.ReadAsStringAsync()}"); + } + + } + } + return await OnGetAsync(); + } + + public async Task OnDeleteReport(int id) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/comment/report/{id}"); + + if (response.StatusCode != HttpStatusCode.OK) + { + return Redirect($"/login?redirect={Request.Path}&error={await response.Content.ReadAsStringAsync()}"); + } + + } + } + return await OnGetAsync(); + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml b/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml new file mode 100644 index 00000000..cb0e7934 --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml @@ -0,0 +1,171 @@ +@page +@model GanjooRazor.Areas.User.Pages.ReviewSongsModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_Layout"; + ViewData["Title"] = "آهنگ‌های پیشنهادی"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); +} +

@ViewData["Title"]

+@if (Model.LastError != "") +{ +

@Model.LastError

+} +else if (@Model.PoemMusicTrackViewModel == null) +{ +

پیشنهادی وجود ندارد.

+} +else if (@Model.Poem == null) +{ +

شعر مرتبط یافت نشد!

+} +else +{ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ شعر: + + @Model.Poem.FullTitle + +
+ @{ + switch (Model.PoemMusicTrackViewModel.TrackType) + { + case RMuseum.Models.Ganjoor.PoemMusicTrackType.Spotify: + اسپاتیفای + break; + case RMuseum.Models.Ganjoor.PoemMusicTrackType.Golha: + گلها + break; + default: + بیپ‌تونز + break; + } + } +
+ خواننده: + +
+
+ نشانی خواننده: + + +
+ +
+ آلبوم: + +
+
+ نشانی آلبوم: + + +
+ آهنگ: + + +
+ نشانی آهنگ: + + +
+ توضیح: + +
+
+ + + + + + + + + + + + + + + + + +
+ +
+ +
+ + +
+
+ +
+ +
+ تعداد کل: + + @Model.TotalCount +
+ +
+ + + +} + +@if(ViewData.ContainsKey("ganjoor-songrevu")) +{ + اضافه کردن آهنگ از منبع دلخواه +} + + diff --git a/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml.cs b/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml.cs new file mode 100644 index 00000000..224dd39c --- /dev/null +++ b/GanjooRazor/Areas/User/Pages/ReviewSongs.cshtml.cs @@ -0,0 +1,151 @@ +using DNTPersianUtils.Core; +using GanjooRazor.Utils; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace GanjooRazor.Areas.User.Pages +{ + public class ReviewSongsModel : PageModel + { + /// + /// Last Error + /// + public string LastError { get; set; } + + /// + /// api model + /// + [BindProperty] + public PoemMusicTrackViewModel PoemMusicTrackViewModel { get; set; } + + /// + /// poem model + /// + public GanjoorPoemCompleteViewModel Poem { get; set; } + + /// + /// skip + /// + public int Skip { get; set; } + + /// + /// total count + /// + public int TotalCount { get; set; } + + /// + /// get + /// + public async Task OnGetAsync() + { + LastError = ""; + TotalCount = 0; + Skip = string.IsNullOrEmpty(Request.Query["skip"]) ? 0 : int.Parse(Request.Query["skip"]); + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var trackResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/song?skip={Skip}&onlyMine=false"); + if (!trackResponse.IsSuccessStatusCode) + { + LastError = await trackResponse.Content.ReadAsStringAsync(); + } + else + { + string paginnationMetadata = trackResponse.Headers.GetValues("paging-headers").FirstOrDefault(); + if (!string.IsNullOrEmpty(paginnationMetadata)) + { + TotalCount = JsonConvert.DeserializeObject(paginnationMetadata).totalCount; + } + + PoemMusicTrackViewModel = JsonConvert.DeserializeObject(await trackResponse.Content.ReadAsStringAsync()); + + PoemMusicTrackViewModel.ArtistName = PoemMusicTrackViewModel.ArtistName.ToPersianNumbers().ApplyCorrectYeKe(); + PoemMusicTrackViewModel.AlbumName = PoemMusicTrackViewModel.AlbumName.ToPersianNumbers().ApplyCorrectYeKe(); + PoemMusicTrackViewModel.TrackName = PoemMusicTrackViewModel.TrackName.ToPersianNumbers().ApplyCorrectYeKe(); + + + var poemResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{PoemMusicTrackViewModel.PoemId}?catInfo=false&rhymes=false&recitations=false&images=false&songs=false&comments=false&verseDetails=false&navigation=false"); + if (poemResponse.IsSuccessStatusCode) + { + Poem = JsonConvert.DeserializeObject(await poemResponse.Content.ReadAsStringAsync()); + + + + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + } + + + public async Task OnPostAsync() + { + + Skip = string.IsNullOrEmpty(Request.Query["skip"]) ? 0 : int.Parse(Request.Query["skip"]); + + if (Request.Form["next"].Count == 1) + { + + return Redirect($"/User/ReviewSongs/?skip={Skip + 1}"); + } + + PoemMusicTrackViewModel.Approved = Request.Form["approve"].Count == 1; + PoemMusicTrackViewModel.Rejected = (Request.Form["reject1"].Count + Request.Form["reject2"].Count + Request.Form["reject3"].Count) > 0; + if(string.IsNullOrEmpty(PoemMusicTrackViewModel.RejectionCause)) + { + if (Request.Form["reject1"].Count == 1) + { + PoemMusicTrackViewModel.RejectionCause = "در آهنگ این شعر خوانده نشده"; + } + else + if (Request.Form["reject2"].Count == 1) + { + PoemMusicTrackViewModel.RejectionCause = "لینک یا اطلاعات آهنگ ایراد دارد"; + } + } + + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + var putResponse = await secureClient.PutAsync($"{APIRoot.Url}/api/ganjoor/song", new StringContent(JsonConvert.SerializeObject(PoemMusicTrackViewModel), Encoding.UTF8, "application/json")); + if (!putResponse.IsSuccessStatusCode) + { + LastError = await putResponse.Content.ReadAsStringAsync(); + } + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + + + if(!string.IsNullOrEmpty(LastError)) + { + return Page(); + } + + return Redirect($"/User/ReviewSongs/?skip={Skip}"); + + } + } +} diff --git a/GanjooRazor/Models/BannerUploadModel.cs b/GanjooRazor/Models/BannerUploadModel.cs new file mode 100644 index 00000000..b48f5c48 --- /dev/null +++ b/GanjooRazor/Models/BannerUploadModel.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Http; + + +namespace GanjooRazor.Models +{ + /// + /// banner upload model + /// + public class BannerUploadModel + { + /// + /// image + /// + public IFormFile Image { get; set; } + + /// + /// altername text + /// + public string Alt { get; set; } + + /// + /// target url + /// + public string Url { get; set; } + } +} diff --git a/GanjooRazor/Models/User/ChangePasswordModel.cs b/GanjooRazor/Models/User/ChangePasswordModel.cs new file mode 100644 index 00000000..2e2cec3a --- /dev/null +++ b/GanjooRazor/Models/User/ChangePasswordModel.cs @@ -0,0 +1,15 @@ +using RSecurityBackend.Models.Auth.ViewModels; + +namespace GanjooRazor.Models.User +{ + /// + /// change password model + /// + public class ChangePasswordModel : SetPasswordModel + { + /// + /// new password model + /// + public string NewPasswordRepeat { get; set; } + } +} diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 71309b8e..fe83c52c 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -19,8 +19,6 @@ using RSecurityBackend.Services.Implementation; using DNTPersianUtils.Core; using System.IO; using RSecurityBackend.Models.Image; -using Microsoft.Data.SqlClient; -using Dapper; namespace RMuseum.Services.Implementation { @@ -58,6 +56,7 @@ namespace RMuseum.Services.Implementation ImageUrl = poet.RImageId == null ? "" : $"/api/ganjoor/poet/image{cat.FullUrl}.png" } ) + .AsNoTracking() .ToListAsync(); StringComparer fa = StringComparer.Create(new CultureInfo("fa-IR"), true); @@ -83,10 +82,10 @@ namespace RMuseum.Services.Implementation { try { - var poet = await _context.GanjoorPoets.Where(p => p.Id == id).FirstOrDefaultAsync(); + var poet = await _context.GanjoorPoets.Where(p => p.Id == id).AsNoTracking().FirstOrDefaultAsync(); if (poet == null) return new RServiceResult(null); - var cat = await _context.GanjoorCategories.Where(c => c.ParentId == null && c.PoetId == id).FirstOrDefaultAsync(); + var cat = await _context.GanjoorCategories.Where(c => c.ParentId == null && c.PoetId == id).AsNoTracking().FirstOrDefaultAsync(); return await GetCatById(cat.Id); } catch (Exception exp) @@ -109,7 +108,7 @@ namespace RMuseum.Services.Implementation { url = url.Substring(0, url.Length - 1); } - var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url && c.ParentId == null).SingleOrDefaultAsync(); + var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url && c.ParentId == null).AsNoTracking().SingleOrDefaultAsync(); if (cat == null) return new RServiceResult(null); return await GetCatById(cat.Id); @@ -134,10 +133,10 @@ namespace RMuseum.Services.Implementation { url = url.Substring(0, url.Length - 1); } - var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url && c.ParentId == null).SingleOrDefaultAsync(); + var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url && c.ParentId == null).AsNoTracking().SingleOrDefaultAsync(); if (cat == null) return new RServiceResult(Guid.Empty); - var poet = await _context.GanjoorPoets.Where(p => p.Id == cat.PoetId).SingleOrDefaultAsync(); + var poet = await _context.GanjoorPoets.Where(p => p.Id == cat.PoetId).AsNoTracking().SingleOrDefaultAsync(); return new RServiceResult((Guid)poet.RImageId); } catch (Exception exp) @@ -161,7 +160,7 @@ namespace RMuseum.Services.Implementation { url = url.Substring(0, url.Length - 1); } - var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url).SingleOrDefaultAsync(); + var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url).AsNoTracking().SingleOrDefaultAsync(); if (cat == null) return new RServiceResult(null); return await GetCatById(cat.Id); @@ -183,7 +182,7 @@ namespace RMuseum.Services.Implementation try { - var cat = await _context.GanjoorCategories.Include(c => c.Poet).Include(c => c.Parent).Where(c => c.Id == id).FirstOrDefaultAsync(); + var cat = await _context.GanjoorCategories.Include(c => c.Poet).Include(c => c.Parent).Where(c => c.Id == id).AsNoTracking().FirstOrDefaultAsync(); if (cat == null) return new RServiceResult(null); @@ -200,7 +199,7 @@ namespace RMuseum.Services.Implementation FullUrl = parent.FullUrl }); - parent = await _context.GanjoorCategories.Where(c => c.Id == parent.ParentId).FirstOrDefaultAsync(); + parent = await _context.GanjoorCategories.Where(c => c.Id == parent.ParentId).AsNoTracking().FirstOrDefaultAsync(); } @@ -223,7 +222,7 @@ namespace RMuseum.Services.Implementation FullUrl = c.FullUrl //other fields null } - ).SingleOrDefaultAsync(); + ).AsNoTracking().SingleOrDefaultAsync(); int preCatId = await _context.GanjoorCategories.Where(c => c.PoetId == cat.PoetId && c.ParentId == cat.ParentId && c.Id < id).AnyAsync() ? @@ -244,7 +243,7 @@ namespace RMuseum.Services.Implementation FullUrl = c.FullUrl //other fields null } - ).SingleOrDefaultAsync(); + ).AsNoTracking().SingleOrDefaultAsync(); GanjoorCatViewModel catViewModel = new GanjoorCatViewModel() { @@ -264,7 +263,7 @@ namespace RMuseum.Services.Implementation UrlSlug = c.UrlSlug, FullUrl = c.FullUrl } - ).ToListAsync(), + ).AsNoTracking().ToListAsync(), Poems = poems ? await _context.GanjoorPoems.Where(p => p.CatId == cat.Id).OrderBy(p => p.Id).Select ( p => new GanjoorPoemSummaryViewModel() @@ -274,7 +273,7 @@ namespace RMuseum.Services.Implementation UrlSlug = p.UrlSlug, Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text } - ).ToListAsync() + ).AsNoTracking().ToListAsync() : null }; @@ -294,7 +293,7 @@ namespace RMuseum.Services.Implementation Nickname = p.Nickname, Published = p.Published, ImageUrl = p.RImageId == null ? "" : $"/api/ganjoor/poet/image{_context.GanjoorCategories.Where(c => c.PoetId == p.Id && c.ParentId == null).Single().FullUrl}.png" - }).FirstOrDefaultAsync(), + }).AsNoTracking().FirstOrDefaultAsync(), Cat = catViewModel } ); @@ -315,7 +314,7 @@ namespace RMuseum.Services.Implementation { try { - var dbPage = await _context.GanjoorPages.Where(p => p.Id == id).SingleOrDefaultAsync(); + var dbPage = await _context.GanjoorPages.Where(p => p.Id == id).AsNoTracking().SingleOrDefaultAsync(); if (dbPage == null) return new RServiceResult(null); //not found return new RServiceResult(dbPage.FullUrl); @@ -347,7 +346,7 @@ namespace RMuseum.Services.Implementation url = url.Substring(0, url.Length - 1); } - var dbPage = await _context.GanjoorPages.Where(p => p.FullUrl == url).SingleOrDefaultAsync(); + var dbPage = await _context.GanjoorPages.Where(p => p.FullUrl == url).AsNoTracking().SingleOrDefaultAsync(); if (dbPage == null) return new RServiceResult(null); //not found var secondPoet = dbPage.SecondPoetId == null ? null : @@ -368,7 +367,7 @@ namespace RMuseum.Services.Implementation ImageUrl = poet.RImageId == null ? "" : $"/api/ganjoor/poet/image{cat.FullUrl}.png" } ) - .SingleAsync(); + .AsNoTracking().SingleAsync(); GanjoorPageCompleteViewModel page = new GanjoorPageCompleteViewModel() { Id = dbPage.Id, @@ -419,6 +418,7 @@ namespace RMuseum.Services.Implementation ((p.PageOrder < dbPage.PageOrder) || (p.PageOrder == dbPage.PageOrder && p.Id < dbPage.Id))) .OrderByDescending(p => p.PageOrder) .ThenByDescending(p => p.Id) + .AsNoTracking() .FirstOrDefaultAsync(); if(pre != null) { @@ -434,6 +434,7 @@ namespace RMuseum.Services.Implementation ((p.PageOrder > dbPage.PageOrder) || (p.PageOrder == dbPage.PageOrder && p.Id > dbPage.Id))) .OrderBy(p => p.PageOrder) .ThenBy(p => p.Id) + .AsNoTracking() .FirstOrDefaultAsync(); if (next != null) { @@ -498,7 +499,7 @@ namespace RMuseum.Services.Implementation PlainText = "", //poem.PlainText HtmlText = "",//poem.HtmlText }; - return new RServiceResult(await source.ToArrayAsync()); + return new RServiceResult(await source.AsNoTracking().ToArrayAsync()); } catch (Exception exp) { @@ -537,7 +538,7 @@ namespace RMuseum.Services.Implementation UserId = comment.UserId }; - GanjoorCommentSummaryViewModel[] allComments = await source.ToArrayAsync(); + GanjoorCommentSummaryViewModel[] allComments = await source.AsNoTracking().ToArrayAsync(); foreach (GanjoorCommentSummaryViewModel comment in allComments) { @@ -784,7 +785,7 @@ namespace RMuseum.Services.Implementation private async Task> _FindReplies(GanjoorComment comment) { - List replies = await _context.GanjoorComments.Where(c => c.InReplyToId == comment.Id).ToListAsync(); + List replies = await _context.GanjoorComments.Where(c => c.InReplyToId == comment.Id).AsNoTracking().ToListAsync(); List replyToReplies = new List(); foreach (GanjoorComment reply in replies) { @@ -1022,7 +1023,7 @@ namespace RMuseum.Services.Implementation AltText = link.AltText, }; - museumImages.AddRange(await externalSrc.ToListAsync()); + museumImages.AddRange(await externalSrc.AsNoTracking().ToListAsync()); for (int i = 0; i < museumImages.Count; i++) { @@ -1092,7 +1093,7 @@ namespace RMuseum.Services.Implementation { try { - var poem = await _context.GanjoorPoems.Include(p => p.GanjoorMetre).Where(p => p.Id == id).SingleOrDefaultAsync(); + var poem = await _context.GanjoorPoems.Include(p => p.GanjoorMetre).Where(p => p.Id == id).AsNoTracking().SingleOrDefaultAsync(); if (poem == null) { return new RServiceResult(null); //not found @@ -1133,7 +1134,7 @@ namespace RMuseum.Services.Implementation UrlSlug = p.UrlSlug, Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text } - ).SingleAsync(); + ).AsNoTracking().SingleAsync(); } } @@ -1163,7 +1164,7 @@ namespace RMuseum.Services.Implementation UrlSlug = p.UrlSlug, Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text } - ).SingleAsync(); + ).AsNoTracking().SingleAsync(); } } @@ -1201,7 +1202,7 @@ namespace RMuseum.Services.Implementation VersePosition = v.VersePosition, Text = v.Text } - ).ToArrayAsync(); + ).AsNoTracking().ToArrayAsync(); }; @@ -1307,7 +1308,7 @@ namespace RMuseum.Services.Implementation RejectionCause = t.RejectionCause } - ).ToArrayAsync() + ).AsNoTracking().ToArrayAsync() ); } catch (Exception exp) @@ -1434,7 +1435,7 @@ namespace RMuseum.Services.Implementation { var song = await _context.GanjoorPoemMusicTracks .Where(p => p.Approved == false && p.Rejected == false && (suggestedById == Guid.Empty || p.SuggestedById == suggestedById)) - .OrderBy(p => p.Id).Skip(skip).FirstOrDefaultAsync(); + .OrderBy(p => p.Id).Skip(skip).AsNoTracking().FirstOrDefaultAsync(); if (song != null) { return new RServiceResult @@ -1639,12 +1640,12 @@ namespace RMuseum.Services.Implementation try { int poemId = _GetRandomPoemId(2); - var poem = await _context.GanjoorPoems.Where(p => p.Id == poemId).SingleOrDefaultAsync(); + var poem = await _context.GanjoorPoems.Where(p => p.Id == poemId).AsNoTracking().SingleOrDefaultAsync(); PublicRecitationViewModel[] recitations = poem == null ? new PublicRecitationViewModel[] { } : (await GetPoemRecitations(poemId)).Result; int loopPreventer = 0; while (poem == null || recitations.Length == 0) { - poem = await _context.GanjoorPoems.Where(p => p.Id == poemId).SingleOrDefaultAsync(); + poem = await _context.GanjoorPoems.Where(p => p.Id == poemId).AsNoTracking().SingleOrDefaultAsync(); recitations = poem == null ? new PublicRecitationViewModel[] { } : (await GetPoemRecitations(poemId)).Result; loopPreventer++; if (loopPreventer > 5) @@ -1751,7 +1752,7 @@ namespace RMuseum.Services.Implementation }, } - ); + ).AsNoTracking(); (PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items) paginatedResult = @@ -1883,7 +1884,7 @@ namespace RMuseum.Services.Implementation } }, } - ); + ).AsNoTracking(); @@ -2036,7 +2037,7 @@ namespace RMuseum.Services.Implementation { try { - return new RServiceResult(await _context.GanjoorMetres.OrderBy(m => m.Rhythm).ToArrayAsync()); + return new RServiceResult(await _context.GanjoorMetres.OrderBy(m => m.Rhythm).AsNoTracking().ToArrayAsync()); } catch(Exception exp) { @@ -2205,7 +2206,7 @@ namespace RMuseum.Services.Implementation AlternateText = b.AlternateText, TargetUrl = b.TargetUrl, Active = b.Active - }).SingleAsync() + }).AsNoTracking().SingleAsync() ); }