コード例 #1
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);
        }
コード例 #2
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);
        }