From 8ffc38b7364dbe72da3cec08c7f3608569674695 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 15 Dec 2023 20:50:05 +0330 Subject: [PATCH] #418 crud in service level --- RMuseum/RMuseum.xml | 14 ++++ .../GanjoorService-QuotedPoems.cs | 75 ++++++++++++++++++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 295551fa..b9fd6a82 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -17481,6 +17481,20 @@ + + + insert quoted poem + + + + + + + update quoted poem + + + + get quoted poems diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs index 7a6c7498..0476f453 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-QuotedPoems.cs @@ -6,6 +6,7 @@ using RSecurityBackend.Models.Generic; using RSecurityBackend.Services.Implementation; using System; using System.Linq; +using System.Security.Policy; using System.Threading.Tasks; namespace RMuseum.Services.Implementation @@ -15,6 +16,76 @@ namespace RMuseum.Services.Implementation /// public partial class GanjoorService : IGanjoorService { + /// + /// insert quoted poem + /// + /// + /// + public async Task> InsertGanjoorQuotedPoemAsync(GanjoorQuotedPoem quoted) + { + try + { + _context.Add(quoted); + await _context.SaveChangesAsync(); + return new RServiceResult(quoted); + + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + + /// + /// update quoted poem + /// + /// + /// + public async Task> UpdateGanjoorQuotedPoemsAsync(GanjoorQuotedPoem quoted) + { + try + { + var dbModel = await _context.GanjoorQuotedPoems.Where(q => q.Id == quoted.Id).SingleAsync(); + dbModel.PoemId = quoted.PoemId; + dbModel.PoetId = quoted.PoetId; + dbModel.RelatedPoetId = quoted.RelatedPoetId; + dbModel.RelatedPoemId = quoted.RelatedPoemId; + dbModel.IsPriorToRelated = quoted.IsPriorToRelated; + dbModel.ChosenForMainList = quoted.ChosenForMainList; + dbModel.CachedRelatedPoemPoetDeathYearInLHijri = quoted.CachedRelatedPoemPoetDeathYearInLHijri; + dbModel.CachedRelatedPoemPoetName = quoted.CachedRelatedPoemPoetName; + dbModel.CachedRelatedPoemPoetUrl = quoted.CachedRelatedPoemPoetUrl; + dbModel.CachedRelatedPoemPoetImage = quoted.CachedRelatedPoemPoetImage; + dbModel.CachedRelatedPoemFullTitle = quoted.CachedRelatedPoemFullTitle; + dbModel.CachedRelatedPoemFullUrl = quoted.CachedRelatedPoemFullUrl; + dbModel.SortOrder = quoted.SortOrder; + dbModel.Note = quoted.Note; + dbModel.Published = quoted.Published; + dbModel.RelatedCoupletVerse1 = quoted.RelatedCoupletVerse1; + dbModel.RelatedCoupletVerse1ShouldBeEmphasized = quoted.RelatedCoupletVerse1ShouldBeEmphasized; + dbModel.RelatedCoupletVerse2 = quoted.RelatedCoupletVerse2; + dbModel.RelatedCoupletVerse2ShouldBeEmphasized = quoted.RelatedCoupletVerse2ShouldBeEmphasized; + dbModel.RelatedCoupletIndex = quoted.RelatedCoupletIndex; + dbModel.CoupletVerse1 = quoted.CoupletVerse1; + dbModel.CoupletVerse1ShouldBeEmphasized = quoted.CoupletVerse1ShouldBeEmphasized; + dbModel.CoupletVerse2 = quoted.CoupletVerse2; + dbModel.CoupletVerse2ShouldBeEmphasized = quoted.CoupletVerse2ShouldBeEmphasized; + dbModel.CoupletIndex = quoted.CoupletIndex; + dbModel.ClaimedByBothPoets = quoted.ClaimedByBothPoets; + dbModel.IndirectQuotation = quoted.IndirectQuotation; + dbModel.SamePoemsQuotedCount = quoted.SamePoemsQuotedCount; + + _context.Update(dbModel); + await _context.SaveChangesAsync(); + return new RServiceResult(true); + + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + /// /// get quoted poems /// @@ -32,7 +103,7 @@ namespace RMuseum.Services.Implementation return new RServiceResult(await _context.GanjoorQuotedPoems .AsNoTracking() - .Where(r => + .Where(r => (poetId == null || r.PoetId == poetId) && (chosen == null || r.ChosenForMainList == chosen) @@ -48,7 +119,7 @@ namespace RMuseum.Services.Implementation .OrderBy(r => r.PoetId).ThenBy(r => r.PoemId).ThenBy(r => r.SortOrder).ThenBy(r => r.CachedRelatedPoemPoetDeathYearInLHijri) .ToArrayAsync() ); - + } catch (Exception exp) {