Beispiel #1
0
 public EventDetailsViewModel(EventDetailsDto eventDto, MoreCommentsDto commentsDto, EventReactionsDto reactions, bool isUserAttending, IEnumerable <RecommendedEventDto> recommendedEvents)
 {
     Id                 = eventDto.Id;
     Name               = eventDto.Name;
     Content            = eventDto.Content;
     AuthorAvatar       = eventDto.AuthorAvatarPath;
     Image              = eventDto.Image;
     Category           = eventDto.Category;
     CityName           = eventDto.CityName;
     StreetName         = eventDto.StreetName;
     Price              = eventDto.Price;
     IsInCalendar       = eventDto.IsInCalendar;
     IsUserSigned       = isUserAttending;
     CreationDate       = eventDto.CreationDate;
     TakesPlaceDate     = eventDto.TakesPlaceDate;
     CreatedBy          = eventDto.CreatedBy;
     CanLoadMore        = commentsDto.CanLoadMore;
     Comments           = commentsDto.CommentsList;
     CommentsCount      = commentsDto.TotalCount;
     Reactions          = reactions.EventReactions;
     ReactionsCount     = reactions.TotalCount;
     CurrentReaction    = reactions.CurrentReaction;
     RecommendedEvents  = recommendedEvents;
     ParticipantsNumber = eventDto.ParticipantsNumber;
     AuthorId           = eventDto.AuthorId;
 }
Beispiel #2
0
        public async Task <EventsPreviewWithLoadDto> GetEventPreviewList(Guid userId, int page = 0, int sizeEvents = 5, int sizeComments = 5, string category = null, string query = null)
        {
            var eventList = await _unitOfWork.EventRepository.GetEventPreviewList(page, sizeEvents, category, query);

            string connectionId = null;

            var found = EventHub.userIdConnectionId.TryGetValue(userId.ToString(), out connectionId);

            foreach (var e in eventList)
            {
                await _hubContext.Groups.AddToGroupAsync(connectionId, $"event-{e.Id}");
            }

            var userAvatarPath = await _unitOfWork.UserRepository.GetUserById(userId.ToString()).ContinueWith(x => x.Result?.AvatarPath);

            var canLoadMore = eventList.Count() > sizeEvents ? true : false;

            eventList = canLoadMore == true?eventList.Take(sizeEvents) : eventList;

            var EventsPreviewDtoList = new EventsPreviewWithLoadDto()
            {
                CanLoadMore = canLoadMore,
                AvatarPath  = userAvatarPath
            };

            foreach (var eventEntity in eventList)
            {
                var userReaction = await _unitOfWork.EventReactionRepository.GetUserReactionAsync(userId, eventEntity.Id);

                var reactions = await _unitOfWork.EventReactionRepository.GetEventReactions(eventEntity.Id);

                var groupedReactions = reactions
                                       .GroupBy(x => x.Type)
                                       .Select(x => new EventReactionDto()
                {
                    Count        = x.Count(),
                    ReactionType = x.Key.ToString().ToLower()
                })
                                       .OrderByDescending(y => y.Count);

                var commentsCount = await _unitOfWork.CommentRepository.GetCommentCountAsync(eventEntity.Id);

                var comments = await _unitOfWork.CommentRepository.GetEventCommentsAsync(eventEntity.Id, 0, sizeComments);

                var commentsDto = comments.Select(x => new CommentDto(x));

                var moreCommentsDto = new MoreCommentsDto(commentsDto, sizeComments)
                {
                    TotalCount = commentsCount
                };

                EventsPreviewDtoList.Events.Add(new EventsPreviewDto(eventEntity, moreCommentsDto)
                {
                    CurrentReaction = userReaction?.Type.ToString().ToLower(),
                    CommentsCount   = commentsCount,
                    Reactions       = groupedReactions,
                    ReactionsCount  = reactions.Count(),
                });
            }
            return(EventsPreviewDtoList);
        }
Beispiel #3
0
 public CommentsListViewModel(MoreCommentsDto commentDtos)
 {
     CanLoadMore  = commentDtos.CanLoadMore;
     CommentsList = commentDtos.CommentsList;
 }