diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index ac1a7417..dd051afe 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -19032,6 +19032,9 @@ IGanjoorService implementation + + IGanjoorService implementation + @@ -19330,6 +19333,14 @@ + + + moderate cat correction + + + + + moderate poem correction diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModerateCatCorrection.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModerateCatCorrection.cs new file mode 100644 index 00000000..87741e3c --- /dev/null +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModerateCatCorrection.cs @@ -0,0 +1,109 @@ +using Microsoft.EntityFrameworkCore; +using RMuseum.Models.Ganjoor; +using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Generic; +using System; +using System.Data; +using System.Linq; +using System.Threading.Tasks; + + +namespace RMuseum.Services.Implementation +{ + /// + /// IGanjoorService implementation + /// + public partial class GanjoorService : IGanjoorService + { + + /// + /// moderate cat correction + /// + /// + /// + /// + public async Task> ModerateCatCorrectionAsync(Guid userId, + GanjoorCatCorrectionViewModel moderation) + { + try + { + var dbCorrection = await _context.GanjoorCatCorrections.Include(c => c.User) + .Where(c => c.Id == moderation.Id) + .FirstOrDefaultAsync(); + + if (dbCorrection == null) + return new RServiceResult(null); + + dbCorrection.ReviewerUserId = userId; + dbCorrection.ReviewDate = DateTime.Now; + dbCorrection.ApplicationOrder = await _context.GanjoorCatCorrections.Where(c => c.Reviewed).AnyAsync() ? 1 + await _context.GanjoorCatCorrections.Where(c => c.Reviewed).MaxAsync(c => c.ApplicationOrder) : 1; + + dbCorrection.AffectedTheCat = false; + dbCorrection.ReviewNote = moderation.ReviewNote; + + int catId = dbCorrection.CatId; + + var dbCat = await _context.GanjoorCategories.Where(c => c.Id == catId).SingleAsync(); + var dbPage = await _context.GanjoorPages.Where(p => p.GanjoorPageType == GanjoorPageType.CatPage && p.CatId == catId).SingleOrDefaultAsync(); + if (dbPage == null) + { + dbPage = await _context.GanjoorPages.Where(p => p.GanjoorPageType == GanjoorPageType.PoetPage && p.PoetId == dbCat.PoetId).SingleAsync(); + } + + GanjoorPageSnapshot snapshot = new GanjoorPageSnapshot() + { + GanjoorPageId = dbPage.Id, + MadeObsoleteByUserId = userId, + RecordDate = DateTime.Now, + Note = $"بررسی پیشنهاد ویرایش بخش با شناسهٔ {dbCorrection.Id}", + Title = dbPage.Title, + UrlSlug = dbPage.UrlSlug, + HtmlText = dbPage.HtmlText, + }; + _context.GanjoorPageSnapshots.Add(snapshot); + await _context.SaveChangesAsync(); + + bool updateCat = false; + if (dbCorrection.DescriptionHtml != null) + { + if (moderation.Result == CorrectionReviewResult.NotReviewed) + return new RServiceResult(null, "تغییرات شرح بررسی نشده است."); + dbCorrection.Result = moderation.Result; + + if (dbCorrection.Result == CorrectionReviewResult.Approved) + { + dbCorrection.AffectedTheCat = true; + dbCat.DescriptionHtml = moderation.DescriptionHtml.Replace("ۀ", "هٔ").Replace("ك", "ک"); + updateCat = true; + } + } + + + if (updateCat) + { + _context.Update(dbCat); + _context.Update(dbPage); + } + + dbCorrection.Reviewed = true; + _context.GanjoorCatCorrections.Update(dbCorrection); + await _context.SaveChangesAsync(); + + await _notificationService.PushNotification(dbCorrection.UserId, + "بررسی ویرایش پیشنهادی شما برای بخش", + $"با سپاس از زحمت و همت شما ویرایش پیشنهادیتان برای {dbPage.FullTitle} بررسی شد.{Environment.NewLine}" + + $"جهت مشاهدهٔ نتیجهٔ بررسی در میز کاربری خود بخش «ویرایش‌های بخش‌های من» را مشاهده بفرمایید.{Environment.NewLine}" + ); + + + + return new RServiceResult(moderation); + + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + } +} diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs index caab3821..c890bc40 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs @@ -1,6 +1,5 @@ using DNTPersianUtils.Core; using Microsoft.EntityFrameworkCore; -using Org.BouncyCastle.Asn1.X509; using RMuseum.DbContext; using RMuseum.Models.Ganjoor; using RMuseum.Models.Ganjoor.ViewModels;