fixes and improvements
This commit is contained in:
parent
b125c66691
commit
d21eca9136
@ -1,4 +1,5 @@
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RSecurityBackend.Models.Auth.Db;
|
||||
using RSecurityBackend.Models.Auth.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,12 +15,12 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="poem"></param>
|
||||
public PoemNarrationViewModel(PoemNarration src, GanjoorPoem poem)
|
||||
public PoemNarrationViewModel(PoemNarration src, RAppUser owner, GanjoorPoem poem)
|
||||
{
|
||||
Id = src.Id;
|
||||
OwnerId = src.OwnerId;
|
||||
Owner = src.Owner == null ? null : new PublicRAppUser(src.Owner);
|
||||
Owner = new PublicRAppUser(owner);
|
||||
GanjoorAudioId = src.GanjoorAudioId;
|
||||
GanjoorPostId = src.GanjoorPostId;
|
||||
AudioOrder = src.AudioOrder;
|
||||
@ -77,10 +78,6 @@ 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
|
||||
|
||||
@ -2046,11 +2046,12 @@
|
||||
Poem Narration view model
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Models.GanjoorAudio.ViewModels.PoemNarrationViewModel.#ctor(RMuseum.Models.GanjoorAudio.PoemNarration,RMuseum.Models.Ganjoor.GanjoorPoem)">
|
||||
<member name="M:RMuseum.Models.GanjoorAudio.ViewModels.PoemNarrationViewModel.#ctor(RMuseum.Models.GanjoorAudio.PoemNarration,RSecurityBackend.Models.Auth.Db.RAppUser,RMuseum.Models.Ganjoor.GanjoorPoem)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
<param name="src"></param>
|
||||
<param name="owner"></param>
|
||||
<param name="poem"></param>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PoemNarrationViewModel.Id">
|
||||
@ -2063,11 +2064,6 @@
|
||||
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
|
||||
|
||||
@ -10,6 +10,7 @@ using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.GanjoorAudio;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.UploadSession;
|
||||
using RSecurityBackend.Models.Auth.Db;
|
||||
using RSecurityBackend.Models.Auth.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
@ -39,32 +40,24 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
//whenever I had not a reference to audio.Owner in the final selection it became null, so this strange arrangement is not all because of my stupidity!
|
||||
var source =
|
||||
_context.AudioFiles.Include(a => a.Owner)
|
||||
from audio in _context.AudioFiles
|
||||
.Include(a => a.Owner)
|
||||
.Where(a =>
|
||||
(filteredUserId == Guid.Empty || a.OwnerId == filteredUserId)
|
||||
&&
|
||||
(status == AudioReviewStatus.All || a.ReviewStatus == status)
|
||||
)
|
||||
.OrderByDescending(a => a.UploadDate)
|
||||
.Select(a => new PoemNarrationViewModel(a, null));
|
||||
join poem in _context.GanjoorPoems
|
||||
on audio.GanjoorPostId equals poem.Id
|
||||
select new PoemNarrationViewModel(audio, audio.Owner, poem);
|
||||
|
||||
(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));
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, PoemNarrationViewModel[] Items)>(paginatedResult);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
@ -81,13 +74,14 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
try
|
||||
{
|
||||
//whenever I had not a reference to audio.Owner in the final selection it became null, so this strange arrangement is not all because of my stupidity!
|
||||
var source =
|
||||
from audio in _context.AudioFiles
|
||||
.Include(a => a.Owner)
|
||||
.Where(a => a.Id == id)
|
||||
join poem in _context.GanjoorPoems
|
||||
on audio.GanjoorPostId equals poem.Id
|
||||
select new PoemNarrationViewModel(audio, poem);
|
||||
select new PoemNarrationViewModel(audio, audio.Owner, poem);
|
||||
|
||||
var narration = await source.SingleOrDefaultAsync();
|
||||
return new RServiceResult<PoemNarrationViewModel>(narration);
|
||||
@ -147,6 +141,9 @@ namespace RMuseum.Services.Implementation
|
||||
))
|
||||
{
|
||||
connection.Open();
|
||||
//I thought that result Id fields would become corresponant to order of selection (and later insertions) but it is not
|
||||
//the case in batch insertion, so this ORDER BY clause is useless unless we do save every time we insert a record
|
||||
//which I guess might take much longer
|
||||
using(MySqlDataAdapter src = new MySqlDataAdapter(
|
||||
"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, " +
|
||||
|
||||
Loading…
Reference in New Issue
Block a user