예제 #1
0
        public async Task<User> AddOrUpdateAsync(User user)
        {
            if (user != null)
            {
                if (user.Id == null)
                {
                    user.Id = Guid.NewGuid().ToString();
                }
                await _userRepository.AddOrUpdateAsync(user);
            }

            return user;
        }
 private static User MapHashToUser(IEnumerable<HashEntry> userHash)
 {
     var user = new User();
     foreach (var entry in userHash)
     {
         if (UserPropertySetters.ContainsKey(entry.Name))
         {
             var setUserProperty = UserPropertySetters[entry.Name];
             setUserProperty(user, entry.Value);
         }
     }
     return user;
 }
        public async Task<User> AddOrUpdateAsync(User user)
        {
            var db = _redis.GetDatabase();
            var userIdKey = GetUserIdKey(user.Id);

            await db.HashSetAsync(userIdKey, MapUserToHashEntries(user).ToArray());
            if (user.ReminderTimeInMinutes == null)
            {
                await db.HashDeleteAsync(userIdKey, "reminderTimeInMinutes");
            }
            await db.StringSetAsync(GetPhoneNumberKey(user.PhoneNumber), user.Id);

            return user;
        }
        public async Task<string> GetCopyrightInfoAsync(User user)
        {
            var chapter = _bibleMetadataService.GetChapterByNumber(user.ChapterNumber);

            var restClient = CreateDbtRestClient();
            var request = new RestRequest("library/metadata");
            request.AddParameter("dam_id", GetDamId(user, chapter));

            var response = await restClient.ExecuteGetTaskAsync<List<CopyrightInfo>>(request);
            var copyrightInfo = response.Data.FirstOrDefault();

            string text = null;
            if (copyrightInfo != null)
            {
                text = copyrightInfo.Mark;
                if (string.IsNullOrEmpty(text))
                {
                    var holder = copyrightInfo.Organization.FirstOrDefault(x => x.OrganizationRole == "holder");
                    if (holder != null)
                    {
                        text = holder.Organization;
                    }
                }
            }
            return text;
        }
 public Task<string> GetContentUrlAsync(User user)
 {
     var chapter = _bibleMetadataService.GetChapterByNumber(user.ChapterNumber);
     return Task.WhenAll(GetBaseAudioUrl(), GetAudioUrl(user, chapter))
         .ContinueWith(x => string.Join("/", x.Result));
 }
 private string GetDamId(User user, Chapter chapter)
 {
     return string.Concat(
         user.AudioVolumeCode,
         GetCollectionId(chapter),
         user.IsDramaticAudioSelected ? '2' : '1',
         MediaType);
 }
        private async Task<string> GetAudioUrl(User user, Chapter chapter)
        {
            var restClient = CreateDbtRestClient();
            var request = new RestRequest("audio/path");
            request.AddParameter("dam_id", GetDamId(user, chapter));
            request.AddParameter("book_id", chapter.Book.DbpId);
            request.AddParameter("chapter_id", chapter.ChapterNumber);

            var response = await restClient.ExecuteGetTaskAsync<List<AudioPath>>(request);
            var path = response.Data.FirstOrDefault();

            if (path == null)
            {
                throw new Exception("Unable to determine audio URL.");
            }

            return path.Path;
        }
        private static IEnumerable<HashEntry> MapUserToHashEntries(User user)
        {
            var hashEntries = new List<HashEntry>
            {
                new HashEntry("phoneNumber", user.PhoneNumber),
                new HashEntry("chapterNumber", user.ChapterNumber),
                new HashEntry("audioVolumeCode", user.AudioVolumeCode),
                new HashEntry("isDramaticAudioSelected", user.IsDramaticAudioSelected),
            };

            if (user.ReminderTimeInMinutes != null)
            {
                hashEntries.Add(new HashEntry("reminderTimeInMinutes", user.ReminderTimeInMinutes));
            }

            return hashEntries;
        }