Esempio n. 1
0
        private IIntranetActivity GetActivity(Guid id)
        {
            var activityType = _activityTypeHelper.GetActivityType(id);
            var service      = GetActivityService(activityType);

            return(service.Get(id));
        }
Esempio n. 2
0
        private async Task <bool> CanAddRemoveLikeAsync(Guid entityId, IntranetEntityTypeEnum entityType)
        {
            if (entityType.Is(IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Events))
            {
                var member = await _intranetMemberService.GetCurrentMemberAsync();

                var activityGroupId = _groupActivityService.GetGroupId(entityId);

                if (activityGroupId.HasValue)
                {
                    var group = _groupService.Get(activityGroupId.Value);
                    if (group == null || group.IsHidden)
                    {
                        return(false);
                    }
                }

                if (activityGroupId.HasValue && !member.GroupIds.Contains(activityGroupId.Value))
                {
                    return(false);
                }
            }
            else if (entityType.Is(IntranetEntityTypeEnum.Comment))
            {
                var comment = await _commentsService.GetAsync(entityId);

                var activityType = _activityTypeHelper.GetActivityType(comment.ActivityId);

                return(await CanAddRemoveLikeAsync(comment.ActivityId, (IntranetEntityTypeEnum)activityType));
            }

            return(true);
        }
        public override ConverterResponseModel MapViewModel(LikesPanelModel node, LikesPanelViewModel viewModel)
        {
            var activityId = _context.ParseQueryString("id").TryParseGuid();

            var activityType = activityId.HasValue
                ? _activityTypeHelper.GetActivityType(activityId.Value)
                : IntranetActivityTypeEnum.ContentPage;

            var id = activityType.Equals(IntranetActivityTypeEnum.ContentPage)
                ? _requestContext.Node?.Key
                : activityId;

            if (!id.HasValue)
            {
                return(NotFoundResult());
            }

            var groupId = _groupActivityService.GetGroupId(id.Value);

            var currentMember = _intranetMemberService.GetCurrentMember();

            viewModel.IsGroupMember = !groupId.HasValue || currentMember.GroupIds.Contains(groupId.Value);

            if (!viewModel.IsGroupMember)
            {
                return(ForbiddenResult());
            }

            var likes = _likesService.GetLikeModels(id.Value).ToArray();

            viewModel.Likes              = likes;
            viewModel.EntityId           = id.Value;
            viewModel.LikedByCurrentUser = likes.Any(el => el.UserId == currentMember.Id);
            viewModel.ActivityType       = activityType;

            return(OkResult());
        }
Esempio n. 4
0
        public override ConverterResponseModel MapViewModel(CommentsPanelModel node, CommentsPanelViewModel viewModel)
        {
            var activityId = _context.ParseQueryString("id").TryParseGuid();

            var activityType = activityId.HasValue
                ? _activityTypeHelper.GetActivityType(activityId.Value)
                : IntranetEntityTypeEnum.ContentPage;

            var id = activityType.Equals(IntranetEntityTypeEnum.ContentPage)
                ? _requestContext.Node?.Key
                : activityId;

            if (!id.HasValue)
            {
                return(NotFoundResult());
            }

            var groupId = _groupActivityService.GetGroupId(id.Value);

            var currentMember = _intranetMemberService.GetCurrentMember();

            viewModel.IsGroupMember = !groupId.HasValue || currentMember.GroupIds.Contains(groupId.Value);

            if (!viewModel.IsGroupMember)
            {
                return(ForbiddenResult());
            }

            var comments = _commentsService.GetMany(id.Value);

            viewModel.Comments     = _commentsHelper.GetCommentViews(comments);
            viewModel.EntityId     = id.Value;
            viewModel.CommentsType = activityType;

            return(OkResult());
        }
        public TService GetService <TService>(Guid activityId) where TService : class, ITypedService
        {
            var activityType = _activityTypeHelper.GetActivityType(activityId);

            return(GetService <TService>(activityType));
        }