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)); } }
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); } }
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); } }
/// <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)); }
/// <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)); }