From 556b4df6387c6c729816758089dffacef3876376 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 27 Oct 2020 20:00:45 +0330 Subject: [PATCH] fixes and improvements --- .../ViewModels/PoemNarrationViewModel.cs | 14 ++++++-- RMuseum/RMuseum.xml | 5 +++ .../Implementation/AudioNarrationService.cs | 33 +++++++++++-------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/RMuseum/Models/GanjoorAudio/ViewModels/PoemNarrationViewModel.cs b/RMuseum/Models/GanjoorAudio/ViewModels/PoemNarrationViewModel.cs index a7177691..e18e2932 100644 --- a/RMuseum/Models/GanjoorAudio/ViewModels/PoemNarrationViewModel.cs +++ b/RMuseum/Models/GanjoorAudio/ViewModels/PoemNarrationViewModel.cs @@ -18,6 +18,7 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels public PoemNarrationViewModel(PoemNarration src, GanjoorPoem poem) { Id = src.Id; + OwnerId = src.OwnerId; Owner = src.Owner == null ? null : new PublicRAppUser(src.Owner); GanjoorAudioId = src.GanjoorAudioId; GanjoorPostId = src.GanjoorPostId; @@ -38,8 +39,12 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels ReviewStatus = src.ReviewStatus; UploadDate = src.UploadDate; ReviewDate = src.ReviewDate; - PoemFullTitle = poem.FullTitle; - PoemFullUrl = poem.FullUrl; + if(poem != null) + { + PoemFullTitle = poem.FullTitle; + PoemFullUrl = poem.FullUrl; + } + List lst = new List(); foreach(AudioSyncStatus status in new AudioSyncStatus[] @@ -72,6 +77,11 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels /// public PublicRAppUser Owner { get; set; } + /// + /// Owner Id + /// + public Guid OwnerId { get; set; } + /// /// Final data is actually exported to a MySQL database which this auto increment field is its key /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index a756b3a2..53d36eed 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -2063,6 +2063,11 @@ Owner User + + + Owner Id + + Final data is actually exported to a MySQL database which this auto increment field is its key diff --git a/RMuseum/Services/Implementation/AudioNarrationService.cs b/RMuseum/Services/Implementation/AudioNarrationService.cs index 0e6f1e11..24b0dc52 100644 --- a/RMuseum/Services/Implementation/AudioNarrationService.cs +++ b/RMuseum/Services/Implementation/AudioNarrationService.cs @@ -1,6 +1,7 @@ using Dapper; using ganjoor; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using MySql.Data.MySqlClient; @@ -10,6 +11,7 @@ using RMuseum.Models.Ganjoor; using RMuseum.Models.GanjoorAudio; using RMuseum.Models.GanjoorAudio.ViewModels; using RMuseum.Models.UploadSession; +using RSecurityBackend.Models.Auth.ViewModels; using RSecurityBackend.Models.Generic; using RSecurityBackend.Services.Implementation; using System; @@ -38,28 +40,31 @@ namespace RMuseum.Services.Implementation { try { - var narrations = _context.AudioFiles - .Include(a => a.Owner) + + var source = + _context.AudioFiles.Include(a => a.Owner) .Where(a => (filteredUserId == Guid.Empty || a.OwnerId == filteredUserId) && (status == AudioReviewStatus.All || a.ReviewStatus == status) ) - .OrderByDescending(a => a.Id); - var source = - narrations - .Join( - _context.GanjoorPoems, - audio => audio.GanjoorPostId, - poem => poem.Id, - (audio, poem) => new PoemNarrationViewModel(audio, poem) - ); + .OrderByDescending(a => a.UploadDate) + .Select(a => new PoemNarrationViewModel(a, null)); (PaginationMetadata PagingMeta, PoemNarrationViewModel[] Items) paginatedResult = await QueryablePaginator.Paginate(source, paging); - - + var commonOwner = filteredUserId == Guid.Empty ? null : new PublicRAppUser(await _context.Users.Where(u => u.Id == filteredUserId).SingleOrDefaultAsync()); + foreach (var item in paginatedResult.Items) + { + GanjoorPoem poem = await _context.GanjoorPoems.Where(p => p.Id == item.GanjoorPostId).SingleOrDefaultAsync(); + if(poem != null) + { + item.PoemFullTitle = poem.FullTitle; + item.PoemFullUrl = poem.FullUrl; + } + item.Owner = filteredUserId == Guid.Empty ? new PublicRAppUser(await _context.Users.Where(u => u.Id == item.OwnerId).SingleOrDefaultAsync()) : commonOwner; + } return new RServiceResult<(PaginationMetadata PagingMeta, PoemNarrationViewModel[] Items)>((paginatedResult.PagingMeta, paginatedResult.Items)); } catch (Exception exp) @@ -147,7 +152,7 @@ namespace RMuseum.Services.Implementation "SELECT audio_ID, audio_post_ID, audio_order, audio_xml, audio_ogg, audio_mp3, " + "audio_title, audio_artist, audio_artist_url, audio_src, audio_src_url, audio_guid, " + "audio_fchecksum, audio_mp3bsize, audio_oggbsize, audio_date " + - "FROM adab.ganja_gaudio ORDER BY audio_date", + "FROM ganja_gaudio ORDER BY audio_ID", connection )) {