Пример #1
0
        public void Update(DomainComment domainComment)
        {
            var comment = Mapper.Map <Comment>(domainComment);

            Uow.CommentRepository.Update(comment);
            Uow.Commit();
        }
Пример #2
0
        public async Task <DomainComment> AddCommentAsync(DomainComment domainComment)
        {
            ProjectEntity projectEntity = await _projectRepository.GetAsync(domainComment.ProjectId);

            CheckProject(projectEntity, domainComment.UserId);

            CommentEntity commentEntity = _mapper.Map <DomainComment, CommentEntity>(domainComment);
            await _commentRepository.AddAsync(commentEntity);

            return(CreateDomainComment(commentEntity, projectEntity.UserId));
        }
Пример #3
0
        public async Task <HttpResponseMessage> Delete(string projectId, string commentId)
        {
            var domainComment = new DomainComment
            {
                Id        = commentId,
                ProjectId = projectId,
                UserId    = UserId
            };

            await _commentService.DeleteCommentAsync(domainComment);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #4
0
        private DomainComment CreateDomainComment(CommentEntity commentEntity, string ownerId)
        {
            var userEntity = new UserEntity
            {
                Id    = commentEntity.UserId,
                Name  = _authenticator.GetUserName(),
                Email = _authenticator.GetUserEmail()
            };

            DomainComment comment = _mapper.Map <Tuple <CommentEntity, UserEntity>, DomainComment>(
                new Tuple <CommentEntity, UserEntity>(commentEntity, userEntity));

            comment.OwnerId = ownerId;

            return(comment);
        }
Пример #5
0
        public async Task <HttpResponseMessage> Post(string projectId, CommentModel comment)
        {
            var domainComment = new DomainComment
            {
                ProjectId = projectId,
                UserId    = UserId,
                Body      = comment.Body,
                DateTime  = DateTime.UtcNow
            };

            domainComment = await _commentService.AddCommentAsync(domainComment);

            var avatarUrl = _userAvatarProvider.GetAvatar(new DomainUser {
                Email = domainComment.UserEmail
            });
            var responseComment = _mapper.Map <Tuple <DomainComment, string>, Comment>(
                new Tuple <DomainComment, string>(domainComment, avatarUrl));

            var project = await _projectService.GetAsync(new DomainProject
            {
                Id     = domainComment.ProjectId,
                UserId = domainComment.OwnerId
            });

            // Notify owner about video comments
            if (project.UserId != domainComment.UserId)
            {
                var videoOwner = await _userService.GetAsync(project.UserId);

                // Checks whether video comments notification enabled
                if (videoOwner.NotifyOnVideoComments)
                {
                    // Send notification e-mail
                    try
                    {
                        await _notificationService.SendVideoCommentNotificationAsync(videoOwner, project, domainComment);
                    }
                    catch (Exception e)
                    {
                        Trace.TraceError("Failed to send video comment notification email to address {0} for user {1}: {2}", videoOwner.Email, videoOwner.Id, e);
                    }
                }
            }

            return(Request.CreateResponse(HttpStatusCode.Created, responseComment));
        }
Пример #6
0
        public async Task DeleteCommentAsync(DomainComment domainComment)
        {
            ProjectEntity projectEntity = await _projectRepository.GetAsync(domainComment.ProjectId);

            CheckProject(projectEntity, domainComment.UserId);

            CommentEntity commentEntity = await _commentRepository.GetAsync(domainComment.Id);

            if (commentEntity == null)
            {
                throw new NotFoundException();
            }
            if (commentEntity.UserId != domainComment.UserId)
            {
                throw new ForbiddenException();
            }

            await _commentRepository.DeleteAsync(commentEntity.Id);
        }
Пример #7
0
        public async Task <HttpResponseMessage> Put(string projectId, string commentId, CommentModel comment)
        {
            var domainComment = new DomainComment
            {
                Id        = commentId,
                ProjectId = projectId,
                UserId    = UserId,
                Body      = comment.Body
            };

            domainComment = await _commentService.EditCommentAsync(domainComment);

            var avatarUrl = _userAvatarProvider.GetAvatar(new DomainUser {
                Email = domainComment.UserEmail
            });
            var responseComment = _mapper.Map <Tuple <DomainComment, string>, Comment>(
                new Tuple <DomainComment, string>(domainComment, avatarUrl));

            return(Request.CreateResponse(HttpStatusCode.OK, responseComment));
        }
Пример #8
0
        public async Task <DomainComment> EditCommentAsync(DomainComment domainComment)
        {
            ProjectEntity projectEntity = await _projectRepository.GetAsync(domainComment.ProjectId);

            CheckProject(projectEntity, domainComment.UserId);

            CommentEntity commentEntity = await _commentRepository.GetAsync(domainComment.Id);

            if (commentEntity == null)
            {
                throw new NotFoundException();
            }
            if (commentEntity.UserId != domainComment.UserId)
            {
                throw new ForbiddenException();
            }
            commentEntity.Body = domainComment.Body;

            await _commentRepository.UpdateAsync(commentEntity);

            return(CreateDomainComment(commentEntity, projectEntity.UserId));
        }
Пример #9
0
        public void Create(DomainComment domainComment, int userId, string kind)
        {
            domainComment.Date   = DateTime.Now;
            domainComment.UserId = userId;
            var comment = Mapper.Map <Comment>(domainComment);

            /*switch (kind)
             * {
             *  case "gift":
             *  {
             *      comment.WishListId = null;
             *      break;
             *  }
             *  case "wishList":
             *  {
             *      comment.GiftId = null;
             *      break;
             *  }
             * }*/

            Uow.CommentRepository.Insert(comment);
            Uow.Commit();
        }
Пример #10
0
        public Task SendVideoCommentNotificationAsync(DomainUser user, DomainProject project, DomainComment domainComment)
        {
            var email = new SendEmailDomain
            {
                Address     = _settings.EmailAddressInfo,
                DisplayName = Emails.SenderDisplayName,
                Emails      = new List <string> {
                    user.Email
                },
                Subject = Emails.SubjectVideoComment,
                UserId  = user.Id,
                Body    = string.Format(PortalResources.VideoCommentNotification,
                                        user.Name,
                                        _userUriProvider.GetUri(domainComment.UserId),
                                        domainComment.UserName,
                                        _projectUriProvider.GetUri(project.Id),
                                        project.Name,
                                        domainComment.Body,
                                        _settings.PortalUri)
            };

            // Send email on user registration
            return(_emailSenderService.SendEmailAsync(email));
        }
Пример #11
0
        public async Task <IEnumerable <ExampleProject> > GetSequenceAsync(DataQueryOptions filter)
        {
            // Get example managers
            List <DomainUser> users = await _adminUserService.GetUsersInRoleAsync(DomainRoles.ExamplesManager);

            if (users.Count == 0)
            {
                return(new List <ExampleProject>());
            }

            // Get their projects
            IEnumerable <DomainProject> projects = await _projectService.GetProjectListByUsersAsync(users);

            // Only public videos
            projects = projects.Where(p => p.Access == ProjectAccess.Public);

            // Paging
            if (filter.Skip.HasValue)
            {
                projects = projects.Skip(filter.Skip.Value);
            }
            if (filter.Take.HasValue)
            {
                projects = projects.Take(filter.Take.Value);
            }

            // Sorting
            if (string.Compare(filter.OrderBy, NameOfHelper.PropertyName <ExampleProject>(x => x.Created),
                               StringComparison.OrdinalIgnoreCase) == 0)
            {
                projects = filter.OrderByDirection == OrderByDirections.Asc
                    ? projects.OrderBy(p => p.Created)
                    : projects.OrderByDescending(p => p.Created);
            }

            List <DomainProject> result = projects.ToList();

            // Aggregating project data
            List <Task <ExampleProject> > tasks = result.Select(GetProjectAsync).ToList();
            await Task.WhenAll(tasks);

            List <ExampleProject> examples = tasks.Select(t => t.Result).ToList();


            // Post-processing

            // Get comments and total comment counts
            string[] projectIds = result.Select(p => p.Id).ToArray();
            Dictionary <string, int> commentsCounts = (await _commentRepository.GetCommentsCountByProjectsAsync(projectIds)).ToDictionary(c => c.ProjectId, c => c.CommentsCount);
            Dictionary <string, List <CommentEntity> > recentComments = await _commentRepository.GetRecentCommentsByProjectsAsync(projectIds, RecentCommentsLimit);

            // Get related users list
            var userIdsSet = new HashSet <string>();

            foreach (var projectComment in recentComments)
            {
                foreach (CommentEntity c in projectComment.Value)
                {
                    if (userIdsSet.Contains(c.UserId))
                    {
                        continue;
                    }

                    userIdsSet.Add(c.UserId);
                }
            }
            Dictionary <string, UserEntity> commentUsers = (await _userRepository.GetUsersByIdsAsync(userIdsSet.ToArray())).ToDictionary(u => u.Id);

            // Append comments data to exmaples
            foreach (ExampleProject example in examples)
            {
                // comments total count
                example.Comments = commentsCounts.ContainsKey(example.Id) ? commentsCounts[example.Id] : 0;

                // comments list
                if (recentComments.ContainsKey(example.Id))
                {
                    var exampleComments = new List <Comment>();
                    List <CommentEntity> projectComments = recentComments[example.Id];
                    foreach (CommentEntity projectComment in projectComments)
                    {
                        UserEntity    commentAuthor = commentUsers.ContainsKey(projectComment.UserId) ? commentUsers[projectComment.UserId] : null;
                        DomainComment domainComment = _mapper.Map <Tuple <CommentEntity, UserEntity>, DomainComment>(new Tuple <CommentEntity, UserEntity>(projectComment, commentAuthor));

                        Comment comment = _mapper.Map <DomainComment, Comment>(domainComment);
                        if (commentAuthor != null)
                        {
                            comment.AvatarUrl = _userAvatarProvider.GetAvatar(commentAuthor.Email);
                        }

                        exampleComments.Add(comment);
                    }

                    exampleComments.Reverse();
                    example.CommentList = exampleComments;
                }
                else
                {
                    example.CommentList = new List <Comment>();
                }
            }

            return(examples);
        }
Пример #12
0
 public static string GetStreamName(this DomainComment comment) => $"{comment.QuestionId}-{comment.CommentId}";
Пример #13
0
 public static string GetBucketName(this DomainComment comment) => Constants.COMMENT_BUCKET;
Пример #14
0
        private Watch AggregateProject(ProjectEntity projectEntity, string userId, Dictionary <string, UserEntity> users, Dictionary <string, int> commentsCounts,
                                       Dictionary <string, List <CommentEntity> > comments)
        {
            DomainProject project = _mapper.Map <ProjectEntity, DomainProject>(projectEntity);

            // 1. Aggregate Data

            UserEntity           projectUser     = users.ContainsKey(project.UserId) ? users[project.UserId] : null;
            int                  commentsCount   = commentsCounts.ContainsKey(project.Id) ? commentsCounts[project.Id] : 0;
            List <CommentEntity> projectComments = comments.ContainsKey(project.Id) ? comments[project.Id] : new List <CommentEntity>();


            // Processed Videos
            var watchVideos = new List <WatchVideo>();

            watchVideos.AddRange(
                from @group in project.EncodedVideos.GroupBy(q => q.Width)
                select @group.ToList()
                into processedVideos
                where processedVideos.Count == 2
                from v in processedVideos
                select new WatchVideo
            {
                ContentType = v.ContentType,
                Width       = v.Width,
                Height      = v.Height,
                Uri         = _uriProvider.CreateUri(v.FileId)
            });

            // Processed Screenshots
            List <WatchScreenshot> watchScreenshots = project.EncodedScreenshots.Select(
                s => new WatchScreenshot
            {
                ContentType = s.ContentType,
                Uri         = _uriProvider.CreateUri(s.FileId)
            }).ToList();

            // External Video
            ExternalVideo externalVideo = !string.IsNullOrEmpty(project.VideoSource)
                ? new ExternalVideo
            {
                ProductName  = project.VideoSourceProductName,
                VideoUri     = project.VideoSource,
                AcsNamespace = _settings.AcsNamespace
            }
                : null;


            // 2. Calculate Video State
            WatchState state;

            if (string.IsNullOrEmpty(project.AvsxFileId) || (string.IsNullOrEmpty(project.OriginalVideoFileId) && externalVideo == null))
            {
                state = WatchState.Uploading;
            }
            else if (externalVideo == null && watchVideos.Count == 0)
            {
                state = WatchState.Encoding;
            }
            else
            {
                state = WatchState.Ready;
            }

            // 3. Map comments
            var watchComments = new List <Comment>();

            foreach (CommentEntity projectComment in projectComments)
            {
                UserEntity    commentAuthor = users.ContainsKey(projectComment.UserId) ? users[projectComment.UserId] : null;
                DomainComment domainComment = _mapper.Map <Tuple <CommentEntity, UserEntity>, DomainComment>(new Tuple <CommentEntity, UserEntity>(projectComment, commentAuthor));

                Comment comment = _mapper.Map <DomainComment, Comment>(domainComment);
                if (commentAuthor != null)
                {
                    comment.AvatarUrl = _userAvatarProvider.GetAvatar(commentAuthor.Email);
                }

                watchComments.Add(comment);
            }
            watchComments.Reverse();

            // Result
            return(new Watch
            {
                Name = project.Name,
                UserId = project.UserId,
                UserName = projectUser != null ? projectUser.Name : null,
                UserAvatarUrl = projectUser != null?_userAvatarProvider.GetAvatar(new DomainUser { Email = projectUser.Email }) : null,
                                    Description = project.Description,
                                    Created = project.Created,
                                    Avsx = !string.IsNullOrEmpty(project.AvsxFileId) ? _uriProvider.CreateUri(project.AvsxFileId) : null,
                                    Screenshots = watchScreenshots,
                                    Videos = watchVideos,
                                    PublicUrl = _projectUriProvider.GetUri(project.Id),
                                    Id = project.Id,
                                    Access = project.Access,
                                    IsEditable = project.UserId == userId,
                                    HitsCount = project.HitsCount,
                                    External = externalVideo,
                                    ScreenshotUrl = !string.IsNullOrEmpty(project.ScreenshotFileId) ? _uriProvider.CreateUri(project.ScreenshotFileId) : null,
                                    State = state,
                                    Generator = (int)project.ProductType,
                                    ProjectType = project.ProjectType,
                                    ProjectSubtype = project.ProjectSubtype,
                                    EnableComments = project.EnableComments,
                                    CommentsCount = commentsCount,
                                    LikesCount = project.LikesCount,
                                    DislikesCount = project.DislikesCount,
                                    Comments = watchComments
            });
        }