Ejemplo n.º 1
0
        public async Task <IssueComments> AddComment([FromBody] NewIssueCommentViewModel comment)
        {
            var user = await _userManager.Users.Where(x => User.Identity.Name.Equals(x.UserName, StringComparison.InvariantCultureIgnoreCase))
                       .FirstOrDefaultAsync();

            var issue = await _issues.GetAll().Include(x => x.UserReported).Include(x => x.IssueCategory).FirstOrDefaultAsync(x => x.Id == comment.IssueId);

            if (issue == null)
            {
                return(null);
            }
            var newComment = new IssueComments
            {
                Comment  = comment.Comment,
                Date     = DateTime.UtcNow,
                UserId   = user.Id,
                IssuesId = comment.IssueId,
            };

            var notificationModel = new NotificationOptions
            {
                RequestId        = issue.RequestId ?? 0,
                DateTime         = DateTime.Now,
                NotificationType = NotificationType.IssueComment,
                RequestType      = issue.RequestType,
                UserId           = user.Id
            };

            var isAdmin = await _userManager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser;

            AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported.UserAlias);
            notificationModel.Substitutes.Add("NewIssueComment", comment.Comment);
            notificationModel.Substitutes.Add("IssueId", comment.IssueId.ToString());
            notificationModel.Substitutes.Add("AdminComment", isAdmin.ToString());

            if (isAdmin)
            {
                // Send to user
                notificationModel.Recipient = issue.UserReported.Email;
            }
            else
            {
                notificationModel.Recipient = user.Email;
            }

            await _notification.Notify(notificationModel);

            return(await _issueComments.Add(newComment));
        }
Ejemplo n.º 2
0
        public async Task <IssueComments> AddComment([FromBody] NewIssueCommentViewModel comment)
        {
            var user = await _userManager.Users.Where(x => User.Identity.Name == x.UserName)
                       .FirstOrDefaultAsync();

            var issue = await _issues.GetAll().Include(x => x.UserReported).FirstOrDefaultAsync(x => x.Id == comment.IssueId);

            if (issue == null)
            {
                return(null);
            }
            var newComment = new IssueComments
            {
                Comment  = comment.Comment,
                Date     = DateTime.UtcNow,
                UserId   = user.Id,
                IssuesId = comment.IssueId,
            };

            var notificationModel = new NotificationOptions
            {
                RequestId        = issue.RequestId ?? 0,
                DateTime         = DateTime.Now,
                NotificationType = NotificationType.IssueComment,
                RequestType      = issue.RequestType,
                UserId           = user.Id
            };

            var isAdmin = await _userManager.IsInRoleAsync(user, OmbiRoles.Admin);

            AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported.UserAlias);
            notificationModel.Substitutes.Add("NewIssueComment", comment.Comment);
            notificationModel.Substitutes.Add("AdminComment", isAdmin.ToString());

            if (isAdmin)
            {
                // Send to user
                notificationModel.Recipient = issue.UserReported.Email;
            }
            else
            {
                notificationModel.Recipient = user.Email;
            }

            BackgroundJob.Enqueue(() => _notification.Publish(notificationModel));

            return(await _issueComments.Add(newComment));
        }