/// <summary>
 /// constructor
 /// </summary>
 /// <param name="src"></param>
 /// <param name="appUser"></param>
 /// <param name="poem"></param>
 /// <param name="mistake"></param>
 public RecitationViewModel(Recitation src, RAppUser appUser, GanjoorPoem poem, string mistake)
 {
     Id    = src.Id;
     Owner = new PublicRAppUser()
     {
         Id             = appUser.Id,
         Username       = appUser.UserName,
         Email          = appUser.Email,
         FirstName      = appUser.FirstName,
         SureName       = appUser.SureName,
         PhoneNumber    = appUser.PhoneNumber,
         RImageId       = appUser.RImageId,
         Status         = appUser.Status,
         NickName       = appUser.NickName,
         Website        = appUser.Website,
         Bio            = appUser.Bio,
         EmailConfirmed = appUser.EmailConfirmed
     };
     GanjoorAudioId           = src.GanjoorAudioId;
     GanjoorPostId            = src.GanjoorPostId;
     AudioOrder               = src.AudioOrder;
     FileNameWithoutExtension = src.FileNameWithoutExtension;
     SoundFilesFolder         = src.SoundFilesFolder;
     AudioTitle               = src.AudioTitle;
     AudioArtist              = src.AudioArtist;
     AudioArtistUrl           = src.AudioArtistUrl;
     AudioSrc         = src.AudioSrc;
     AudioSrcUrl      = src.AudioSrcUrl;
     LegacyAudioGuid  = src.LegacyAudioGuid;
     Mp3FileCheckSum  = src.Mp3FileCheckSum;
     Mp3SizeInBytes   = src.Mp3SizeInBytes;
     OggSizeInBytes   = src.OggSizeInBytes;
     LocalMp3FilePath = src.LocalMp3FilePath;
     LocalXmlFilePath = src.LocalXmlFilePath;
     ReviewStatus     = src.ReviewStatus;
     UploadDate       = src.UploadDate;
     FileLastUpdated  = src.FileLastUpdated;
     ReviewDate       = src.ReviewDate;
     if (poem != null)
     {
         PoemFullTitle = poem.FullTitle;
         PoemFullUrl   = poem.FullUrl;
     }
     AudioSyncStatus = src.AudioSyncStatus;
     if (string.IsNullOrEmpty(mistake))
     {
         ReviewMsg = src.ReviewMsg;
     }
     else
     {
         ReviewMsg = mistake;
     }
 }
Beispiel #2
0
        /// <summary>
        /// modify existing user /*update related entities cache*/
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="updateUserInfo"></param>
        /// <returns></returns>
        public override async Task <RServiceResult <bool> > ModifyUser(Guid userId, RegisterRAppUser updateUserInfo)
        {
            try
            {
                RAppUser unmodifiedUserInfo = await _userManager.FindByIdAsync(userId.ToString());

                if (unmodifiedUserInfo == null)
                {
                    return(new RServiceResult <bool>(false, "کاربر مورد نظر یافت نشد"));
                }

                string nickName = updateUserInfo.NickName;

                if (string.IsNullOrEmpty(nickName))
                {
                    return(new RServiceResult <bool>(false, "نام مستعار نمی‌تواند خالی باشد."));
                }

                nickName = nickName.Trim();

                RServiceResult <bool> res = await base.ModifyUser(userId, updateUserInfo);

                if (res.Result)
                {
                    try
                    {
                        if (nickName != updateUserInfo.NickName)
                        {
                            RMuseumDbContext context = _context as RMuseumDbContext;
                            var poemIdSet            = await context.GanjoorComments.AsNoTracking().Where(c => c.UserId == userId).Select(c => c.PoemId).ToListAsync();

                            foreach (var poemId in poemIdSet)
                            {
                                //await _ganjoorService.CacheCleanForPageById(poemId); /*had error in service initializtion, so done it in the dirty way*/

                                var dbPage = await context.GanjoorPages.Where(p => p.Id == poemId).AsNoTracking().SingleOrDefaultAsync();

                                if (dbPage != null)
                                {
                                    //CacheCleanForPageByUrl(dbPage.FullUrl);
                                    var url     = dbPage.FullUrl;
                                    var cachKey = $"GanjoorService::GetPageByUrl::{url}";
                                    if (_memoryCache.TryGetValue(cachKey, out GanjoorPageCompleteViewModel page))
                                    {
                                        _memoryCache.Remove(cachKey);

                                        var poemCachKey = $"GetPoemById({page.Id}, {true}, {false}, {true}, {true}, {true}, {true}, {true}, {true}, {true})";
                                        if (_memoryCache.TryGetValue(poemCachKey, out GanjoorPoemCompleteViewModel p))
                                        {
                                            _memoryCache.Remove(poemCachKey);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        return(new RServiceResult <bool>(true)); //ignore this error! because main operation was successfull!
                    }
                }
                return(res);
            }
            catch (Exception exp)
            {
                return(new RServiceResult <bool>(false, exp.ToString()));
            }
        }