From abfff693f52d6b77eb399e7d943da46d109b2fca Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Wed, 25 Nov 2020 11:46:12 +0330 Subject: [PATCH] chown transfers profiles too now --- .../Implementation/RecitationService.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/RMuseum/Services/Implementation/RecitationService.cs b/RMuseum/Services/Implementation/RecitationService.cs index 4f1d150a..33ca8951 100644 --- a/RMuseum/Services/Implementation/RecitationService.cs +++ b/RMuseum/Services/Implementation/RecitationService.cs @@ -1539,7 +1539,26 @@ namespace RMuseum.Services.Implementation recitation.OwnerId = newOwnerId; } _context.Recitations.UpdateRange(recitations); + var profiles = await _context.UserRecitationProfiles.Where(r => r.UserId == currentOwenerId && r.ArtistName == artistName).ToListAsync(); + foreach(UserRecitationProfile profile in profiles) + { + profile.UserId = newOwnerId; + } + _context.UserRecitationProfiles.UpdateRange(profiles); await _context.SaveChangesAsync(); + + var defProfile = await _context.UserRecitationProfiles.Where(r => r.UserId == newOwnerId && r.IsDefault == true).FirstOrDefaultAsync(); + if(defProfile == null) + { + var firstProfile = await _context.UserRecitationProfiles.Where(r => r.UserId == newOwnerId).FirstOrDefaultAsync(); + if(firstProfile != null) + { + firstProfile.IsDefault = true; + _context.UserRecitationProfiles.Update(firstProfile); + await _context.SaveChangesAsync(); + } + } + return new RServiceResult(recitations.Count); } catch(Exception exp)