fixes and improvements

This commit is contained in:
Hamid Reza Mohammadi 2020-10-27 20:00:45 +03:30
parent ce6012ad62
commit 556b4df638
3 changed files with 36 additions and 16 deletions

View File

@ -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<AudioSyncStatus> lst = new List<AudioSyncStatus>();
foreach(AudioSyncStatus status in
new AudioSyncStatus[]
@ -72,6 +77,11 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
/// </summary>
public PublicRAppUser Owner { get; set; }
/// <summary>
/// Owner Id
/// </summary>
public Guid OwnerId { get; set; }
/// <summary>
/// Final data is actually exported to a MySQL database which this auto increment field is its key
/// </summary>

View File

@ -2063,6 +2063,11 @@
Owner User
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PoemNarrationViewModel.OwnerId">
<summary>
Owner Id
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PoemNarrationViewModel.GanjoorAudioId">
<summary>
Final data is actually exported to a MySQL database which this auto increment field is its key

View File

@ -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<PoemNarrationViewModel>.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
))
{