예제 #1
0
        public async Task <IEnumerable <UserPurchaseDto> > GetUserPurchasesAsync([FromServices] IUrlBuilder urlBuilder, CancellationToken token)
        {
            var userId = _userManager.GetLongUserId(User);
            var query  = new UserPurchasesByIdQuery(userId);
            var result = await _queryBus.QueryAsync(query, token);

            return(result.Select(s =>
            {
                if (s is PurchasedDocumentDto d)
                {
                    d.Preview = urlBuilder.BuildDocumentThumbnailEndpoint(d.Id);
                    d.Url = Url.DocumentUrl(d.Course, d.Id, d.Name);
                }
                return s;
            }));
        }
예제 #2
0
 private WebResponseWithFacet <FeedDto> GenerateResult(
     IEnumerable <FeedDto> result, IEnumerable <string> filters)
 {
     return(new WebResponseWithFacet <FeedDto>
     {
         Result = result.Select(s =>
         {
             if (s is DocumentFeedDto p)
             {
                 p.Preview = _urlBuilder.BuildDocumentThumbnailEndpoint(p.Id);
                 p.Url = Url.DocumentUrl(p.Course, p.Id, p.Title);
             }
             return s;
         }),
         Filters = filters
     });
예제 #3
0
        public async Task <IEnumerable <DocumentFeedDto> > GetTopDocumentsAsync(int count,
                                                                                [FromServices] IUrlBuilder urlBuilder,
                                                                                [ProfileModelBinder(ProfileServiceQuery.Country)] UserProfile profile,
                                                                                CancellationToken token)
        {
            var query  = new TopDocumentsQuery(profile.Country, count);
            var result = await _queryBus.QueryAsync(query, token);

            return(result.Select(item =>
            {
                item.User.Image = _urlBuilder.BuildUserImageEndpoint(item.User.Id, item.User.Image);
                item.Preview = urlBuilder.BuildDocumentThumbnailEndpoint(item.Id);
                item.Url = Url.DocumentUrl(item.Course, item.Id, item.Title);
                return item;
            }));
        }
예제 #4
0
        public async Task <IEnumerable <DocumentFeedDto> > GetAsync(SimilarDocumentsQuery query, CancellationToken token)
        {
            const string sql = @"with cte as
                                (
                                select d.UniversityId, CourseName, u.Country
                                from sb.Document d 
                                join sb.[user] u
	                                on d.UserId = u.Id
                                where d.Id = :Id
                                )

                                select top 10 d.Id, d.UpdateTime as DateTime, d.CourseName as Course, d.Name as Title,  
                                un.Name as University, 
                                coalesce(d.Description, d.MetaContent) as Snippet, d.Views, d.Downloads, d.Price, 
                                d.DocumentType, d.Duration,  
                                (
	                                select count(1)
	                                from sb.[Transaction] t 
	                                where t.TransactionType='Document' and 
	                                t.DocumentId=d.Id
	                                and t.[Action]='SoldDocument'
                                ) as Purchased, 
                                d.VoteCount as [Vote.Votes],
                                u.Id as [User.Id], u.Name as [User.Name], 
                                u.ImageName as [User.Image]
                                from sb.[Document] d 
                                inner join sb.[User] u on d.UserId=u.Id 
                                left outer join sb.[University] un on d.UniversityId=un.Id,
                                cte
                                where d.CourseName = cte.CourseName and u.Country = cte.Country
                                and d.Id != :Id and d.[State]='ok'
                                order by case when d.UniversityId=cte.UniversityId
                                then 1 else 0 end desc, d.DocumentType desc, d.UpdateTime desc;
                                ";

            var res = await _session.CreateSQLQuery(sql)
                      .SetInt64("Id", query.DocumentId)
                      .SetResultTransformer(new DeepTransformer <DocumentFeedDto>('.', new SbAliasToBeanResultTransformer <DocumentFeedDto>()))
                      .ListAsync <DocumentFeedDto>(token);

            return(res.Select(s =>
            {
                s.User.Image = _urlBuilder.BuildUserImageEndpoint(s.User.Id, s.User.Image);
                s.Preview = _urlBuilder.BuildDocumentThumbnailEndpoint(s.Id);
                return s;
            }));
        }
예제 #5
0
        public async Task <object> GeneratePreviewAsync(DocumentDetailDto model, long userId, CancellationToken token)
        {
            string locator;

            if (model.IsPurchased)
            {
                locator = await _videoService.BuildUserStreamingLocatorAsync(model.Document.Id, userId, token);
            }
            else
            {
                locator = await _videoService.GetShortStreamingUrlAsync(model.Document.Id, token);
            }

            var uri = _urlBuilder.BuildDocumentThumbnailEndpoint(model.Document.Id);


            return(new { locator, poster = uri });
        }
예제 #6
0
        public async Task<IEnumerable<SaleDto>> GetUserSalesAsync([FromServices] IUrlBuilder urlBuilder, CancellationToken token)
        {
            var userId = _userManager.GetLongUserId(User);
            var query = new UserSalesByIdQuery(userId);
            var result = await _queryBus.QueryAsync(query, token);

            return result.Select(s =>
            {
                if (s is DocumentSaleDto d)
                {
                    d.Preview = urlBuilder.BuildDocumentThumbnailEndpoint(d.Id);
                    d.Url = Url.DocumentUrl(d.Course, d.Id, d.Name);
                }
                if (s is SessionSaleDto ss)
                {
                    ss.StudentImage = urlBuilder.BuildUserImageEndpoint(ss.StudentId, ss.StudentImage, ss.StudentName);
                }
                return s;
            });
        }
예제 #7
0
        public async Task <WebResponseWithFacet <DocumentFeedDto> > GetDocumentsAsync(
            [FromQuery] ProfileDocumentsRequest request, CancellationToken token = default)
        {
            var query      = new UserDocumentsQuery(request.Id, request.Page, request.PageSize, request.DocumentType, request.Course);
            var retValTask = _queryBus.QueryAsync(query, token);

            var votesTask = Task.FromResult <Dictionary <long, VoteType> >(null);

            if (User.Identity.IsAuthenticated)
            {
                var userId    = _userManager.GetLongUserId(User);
                var queryTags = new UserVotesByCategoryQuery(userId);
                votesTask = _queryBus.QueryAsync(queryTags, token)
                            .ContinueWith(
                    t2 => { return(t2.Result.ToDictionary(x => x.Id, s => s.Vote)); }, token);
            }

            await Task.WhenAll(retValTask, votesTask);

            foreach (var item in retValTask.Result.Result)
            {
                if (item.User != null)
                {
                    item.User.Image = _urlBuilder.BuildUserImageEndpoint(item.User.Id, item.User.Image);
                }
            }
            return(new WebResponseWithFacet <DocumentFeedDto>()
            {
                Result = retValTask.Result.Result.Select(s =>
                {
                    s.Url = Url.DocumentUrl(s.Course, s.Id, s.Title);
                    s.Preview = _urlBuilder.BuildDocumentThumbnailEndpoint(s.Id);
                    if (votesTask.Result != null && votesTask.Result.TryGetValue(s.Id, out var p))
                    {
                        s.Vote.Vote = p;
                    }

                    return s;
                }),
                Count = retValTask.Result.Count
            });