コード例 #1
0
ファイル: ActivityProjector.cs プロジェクト: peternunn/Folium
        private void CreateEmailNotification(IDbTransaction tx, Models.EmailNotification emailNotification)
        {
            var sqlParams = emailNotification.ToDynamic();

            const string sql = @"
				INSERT INTO [dbo].[ActivityProjector.EmailNotification]
					   ([Id]
                       ,[To]
					   ,[Subject]
					   ,[HtmlBody]
                       ,[ActionLink]
                       ,[ActionTitle]
                       ,[When]
                       ,[UserId])
				 SELECT
                        @Id
					   ,@To
					   ,@Subject
					   ,@HtmlBody
                       ,@ActionLink
                       ,@ActionTitle
                       ,@When
                       ,@UserId
				WHERE NOT EXISTS(SELECT * FROM [dbo].[ActivityProjector.EmailNotification] WHERE [UserId] = @UserId AND [When] = @When AND [To] = @To);"                ;
            var          insertedRowCount = tx.Connection.Execute(sql, (object)sqlParams, tx);

            if (insertedRowCount == 1)
            {
                // Schedule the email to be sent on a background thread.
                BackgroundJob.Enqueue <IEmailService>(service => service.SendEmail(emailNotification.Id));
            }
        }
コード例 #2
0
ファイル: ActivityProjector.cs プロジェクト: peternunn/Folium
        private void OnEntryShared(IDbTransaction tx, ICommit commit, EntryShared @event)
        {
            RecordActivity(tx, new Models.Activity {
                UserId = @event.UserId,
                Type   = (int)ActivityType.EntryShared,
                When   = commit.CommitStamp,
                Link   = commit.AggregateId().ToString()
            });

            var author        = _userService.GetUser(@event.UserId, tx);
            var collaborators = @event.CollaboratorIds.Select(collaboratorId => _userService.GetUser(collaboratorId, tx));

            foreach (var collaborator in collaborators)
            {
                var customText   = string.IsNullOrWhiteSpace(@event.Message) ? "" : $"<p>{WebUtility.HtmlEncode(@event.Message)}</p>";
                var notification = new Models.EmailNotification {
                    Id          = Guid.NewGuid(),
                    UserId      = @event.UserId,
                    To          = collaborator.Email,
                    When        = commit.CommitStamp,
                    Subject     = $"{author.FirstName} {author.LastName} has shared an entry with you",
                    HtmlBody    = $"<p>{collaborator.FirstName} {collaborator.LastName},</p> <p>Just to let you know {author.FirstName} {author.LastName} has shared an entry in Folium with you.</p>{customText}",
                    ActionLink  = $"{_applicationConfiguration.Value.BaseUrl}/entries/{commit.AggregateId()}",
                    ActionTitle = "View Entry"
                };
                CreateEmailNotification(tx, notification);
            }
        }
コード例 #3
0
ファイル: ActivityProjector.cs プロジェクト: peternunn/Folium
        private void OnEntryCommentCreated(IDbTransaction tx, ICommit commit, EntryCommentCreated @event)
        {
            RecordActivity(tx, new Models.Activity {
                UserId = @event.CreatedBy,
                Type   = (int)ActivityType.EntryCommentCreated,
                When   = @event.CreatedAt,
                Link   = $"{commit.AggregateId()},{@event.Id}"
            });

            var author        = new UserDto(_userService.GetUser(@event.CreatedBy, tx));
            var collaborators =
                (_entryService.GetCollaborators(commit.AggregateId())).ToArray()
                .Union(new[] { author })
                .Where(c => c.Id != @event.CreatedBy);

            foreach (var collaborator in collaborators)
            {
                var notification = new Models.EmailNotification {
                    Id          = Guid.NewGuid(),
                    UserId      = @event.CreatedBy,
                    To          = collaborator.Email,
                    When        = @event.CreatedAt,
                    Subject     = $"{author.FirstName} {author.LastName} has made a comment",
                    HtmlBody    = $"<p>{collaborator.FirstName} {collaborator.LastName},</p> <p>Just to let you know {author.FirstName} {author.LastName} has made a new comment on an entry in Folium.</p>",
                    ActionLink  = $"{_applicationConfiguration.Value.BaseUrl}/entries/{commit.AggregateId()}?comment-id={@event.Id}",
                    ActionTitle = "View Entry"
                };
                CreateEmailNotification(tx, notification);
            }
        }
コード例 #4
0
 /// <summary>
 /// Replace Encoding Error Email Notification
 /// </summary>
 /// <param name="notificationId">Id of the email notification (required)</param>
 /// <param name="emailNotification">The email notification with the updated values</param>
 public async Task <Models.EmailNotification> UpdateAsync(string notificationId, Models.EmailNotification emailNotification)
 {
     return(await _apiClient.UpdateAsync(notificationId, emailNotification));
 }
コード例 #5
0
 /// <summary>
 /// Add Encoding Error Email Notification (Specific Encoding)
 /// </summary>
 /// <param name="encodingId">Id of the encoding resource (required)</param>
 /// <param name="emailNotification">The email notifications object</param>
 public async Task <Models.EmailNotification> CreateByEncodingIdAsync(string encodingId, Models.EmailNotification emailNotification)
 {
     return(await _apiClient.CreateByEncodingIdAsync(encodingId, emailNotification));
 }