コード例 #1
0
ファイル: CommentService.cs プロジェクト: GusLab/video-portal
        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);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: CommentService.cs プロジェクト: GusLab/video-portal
        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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: CommentService.cs プロジェクト: GusLab/video-portal
        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);
        }