Пример #1
0
        private async Task FetchMedia(int?companyId)
        {
            var task = companyId == null
                ? mediaEntries.FetchCountedMediaEntries(PageNumber, 20)
                : mediaEntries.FetchCountedCompanyMediaEntries(companyId.Value, PageNumber, 20);

            var results = (await task.ConfigureAwait(false))
                          .Ensure(e => e.HasValue, "Media entries found")
                          .OnSuccess(e => e.Value)
                          .OnBoth(e => e.IsSuccess ? e.Value : new PaginatedResult <MediaEntry> {
                Data = new List <MediaEntry>(), Count = 0
            });

            TotalResults = results.Count;
            MediaEntries = results.Data.Select(entry => new MediaFile
            {
                Id           = entry.Id,
                Key          = entry.Key,
                CompanyId    = entry.CompanyId,
                Title        = entry.Title,
                ThumbnailUrl = entry.MediaType == 1 ? new Uri($"https://s3-eu-west-1.amazonaws.com/{settings.Connection.S3BucketName}/images/{entry.CompanyId}__{entry.Key}__img") : null,
                Type         = (MediaFileType)entry.MediaType,
            }).ToList();
        }