From 44f4136020903b56a2948605811cc669c516e130 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 8 Apr 2021 14:23:06 +0430 Subject: [PATCH] #104 page modification method (code not complete and working and a db migration is required which is not yet generated) --- RMuseum/DbContext/RMuseumDbContext.cs | 5 + RMuseum/Models/Ganjoor/GanjoorPageSnapshot.cs | 91 +++++++++++ .../ViewModels/GanjoorModifyPageViewModel.cs | 58 +++++++ RMuseum/RMuseum.xml | 154 ++++++++++++++++++ .../Services/Implementation/GanjoorService.cs | 57 +++++++ 5 files changed, 365 insertions(+) create mode 100644 RMuseum/Models/Ganjoor/GanjoorPageSnapshot.cs create mode 100644 RMuseum/Models/Ganjoor/ViewModels/GanjoorModifyPageViewModel.cs diff --git a/RMuseum/DbContext/RMuseumDbContext.cs b/RMuseum/DbContext/RMuseumDbContext.cs index aca2f31b..f49f018a 100644 --- a/RMuseum/DbContext/RMuseumDbContext.cs +++ b/RMuseum/DbContext/RMuseumDbContext.cs @@ -240,6 +240,11 @@ namespace RMuseum.DbContext /// public DbSet GanjoorReportedComments { get; set; } + /// + /// Ganjoor Page Snapshots + /// + public DbSet GanjoorPageSnapshots { get; set; } + } } diff --git a/RMuseum/Models/Ganjoor/GanjoorPageSnapshot.cs b/RMuseum/Models/Ganjoor/GanjoorPageSnapshot.cs new file mode 100644 index 00000000..9a246095 --- /dev/null +++ b/RMuseum/Models/Ganjoor/GanjoorPageSnapshot.cs @@ -0,0 +1,91 @@ +using RSecurityBackend.Models.Auth.Db; +using System; + +namespace RMuseum.Models.Ganjoor +{ + /// + /// snapshot of ganjoor pages to keep track of their changes + /// + public class GanjoorPageSnapshot + { + /// + /// id + /// + public int Id { get; set; } + + /// + /// ganjoor page id + /// + public int GanjoorPageId { get; set; } + + /// + /// ganjoor page + /// + public GanjoorPage GanjoorPage { get; set; } + + /// + /// id - this record is then modified by this user and made obsolete + /// + public Guid MadeObsoleteByUserId { get; set; } + + /// + /// this record is then modified by this user and made obsolete + /// + public RAppUser MadeObsoleteByUser { get; set; } + + /// + /// record date + /// + public DateTime RecordDate { get; set; } + + /// + /// a description of the modfication + /// + public string Note { get; set; } + + /// + /// title + /// + public string Title { get; set; } + + /// + /// url => slug + /// + public string UrlSlug { get; set; } + + /// + /// Html Text + /// + public string HtmlText { get; set; } + + /// + /// Poem Rhythm + /// + public string Rhythm { get; set; } + + /// + /// rhyme letters + /// + public string RhymeLetters { get; set; } + + /// + /// source name + /// + public string SourceName { get; set; } + + /// + /// source url slug + /// + public string SourceUrlSlug { get; set; } + + /// + /// old collection or book name for Saadi's ghazalyiat (طیبات، خواتیم و ....) + /// + public string OldTag { get; set; } + + /// + /// old collection page url e.g /saadi/tayyebat + /// + public string OldTagPageUrl { get; set; } + } +} diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorModifyPageViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorModifyPageViewModel.cs new file mode 100644 index 00000000..e62dab6d --- /dev/null +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorModifyPageViewModel.cs @@ -0,0 +1,58 @@ +namespace RMuseum.Models.Ganjoor.ViewModels +{ + /// + /// modify page view model + /// + public class GanjoorModifyPageViewModel + { + /// + /// title + /// + public string Title { get; set; } + + /// + /// url => slug + /// + public string UrlSlug { get; set; } + + /// + /// Html Text + /// + public string HtmlText { get; set; } + + /// + /// Poem Rhythm + /// + public string Rhythm { get; set; } + + /// + /// rhyme letters + /// + public string RhymeLetters { get; set; } + + /// + /// source name + /// + public string SourceName { get; set; } + + /// + /// source url slug + /// + public string SourceUrlSlug { get; set; } + + /// + /// old collection or book name for Saadi's ghazalyiat (طیبات، خواتیم و ....) + /// + public string OldTag { get; set; } + + /// + /// old collection page url e.g /saadi/tayyebat + /// + public string OldTagPageUrl { get; set; } + + /// + /// a description of the modfication + /// + public string Note { get; set; } + } +} diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index d452a3ac..84334c43 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1399,6 +1399,11 @@ Ganjoor Reported Comments + + + Ganjoor Page Snapshots + + Items or pictures status @@ -3924,6 +3929,91 @@ post date + + + snapshot of ganjoor pages to keep track of their changes + + + + + id + + + + + ganjoor page id + + + + + ganjoor page + + + + + id - this record is then modified by this user and made obsolete + + + + + this record is then modified by this user and made obsolete + + + + + record date + + + + + a description of the modfication + + + + + title + + + + + url => slug + + + + + Html Text + + + + + Poem Rhythm + + + + + rhyme letters + + + + + source name + + + + + source url slug + + + + + old collection or book name for Saadi's ghazalyiat (طیبات، خواتیم و ....) + + + + + old collection page url e.g /saadi/tayyebat + + Ganjoor Page Type @@ -4530,6 +4620,61 @@ this can be used by clients + + + modify page view model + + + + + title + + + + + url => slug + + + + + Html Text + + + + + Poem Rhythm + + + + + rhyme letters + + + + + source name + + + + + source url slug + + + + + old collection or book name for Saadi's ghazalyiat (طیبات، خواتیم و ....) + + + + + old collection page url e.g /saadi/tayyebat + + + + + a description of the modfication + + Ganjoor Page View Model @@ -7453,6 +7598,15 @@ + + + modify page + + + + + + Database Context diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 26248ae6..339a1246 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -1749,6 +1749,63 @@ namespace RMuseum.Services.Implementation } } + + /// + /// modify page + /// + /// + /// + /// + /// + public async Task> ModifyPage(int id, Guid editingUserId, GanjoorModifyPageViewModel pageData) + { + try + { + var dbPage = await _context.GanjoorPages.Where(p => p.Id == id).SingleOrDefaultAsync(); + if (dbPage == null) + return new RServiceResult(null);//not found + + + + GanjoorPageSnapshot snapshot = new GanjoorPageSnapshot() + { + GanjoorPageId = id, + MadeObsoleteByUserId = editingUserId, + RecordDate = DateTime.Now, + Note = pageData.Note, + Title = dbPage.Title, + UrlSlug = dbPage.UrlSlug, + HtmlText = dbPage.HtmlText, + }; + + GanjoorPoem dbPoem = null; + + if (dbPage.GanjoorPageType == GanjoorPageType.PoemPage) + { + dbPoem = await _context.GanjoorPoems.Include(p => p.GanjoorMetre).Where(p => p.Id == id).SingleOrDefaultAsync(); + + snapshot.SourceName = dbPoem.SourceName; + snapshot.SourceUrlSlug = dbPoem.SourceUrlSlug; + snapshot.Rhythm = dbPoem.GanjoorMetre == null ? null : dbPoem.GanjoorMetre.Rhythm; + snapshot.RhymeLetters = dbPoem.RhymeLetters; + snapshot.OldTag = dbPoem.OldTag; + snapshot.OldTagPageUrl = dbPoem.OldTagPageUrl; + } + + _context.GanjoorPageSnapshots.Add(snapshot); + await _context.SaveChangesAsync(); + + //TODO actula modification goes here: + + + return await GetPageByUrl(dbPage.FullUrl); + } + catch(Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + /// /// Database Context ///