forked from DevBetterCom/DevBetterWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ardalis/warnings as errors (DevBetterCom#73)
* Adding warnings as errors to test project * Adding email notification for new member creation
- Loading branch information
Showing
19 changed files
with
95 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
using DevBetterWeb.Core.SharedKernel; | ||
using System.Threading.Tasks; | ||
|
||
namespace DevBetterWeb.Core.Interfaces | ||
{ | ||
public interface IDomainEventDispatcher | ||
{ | ||
void Dispatch<TEvent>(TEvent domainEvent) where TEvent : BaseDomainEvent; | ||
Task Dispatch(BaseDomainEvent domainEvent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
using DevBetterWeb.Core.SharedKernel; | ||
using System.Threading.Tasks; | ||
|
||
namespace DevBetterWeb.Core.Interfaces | ||
{ | ||
public interface IHandle<T> where T : BaseDomainEvent | ||
{ | ||
void Handle(T domainEvent); | ||
Task Handle(T domainEvent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/DevBetterWeb.Infrastructure/Services/NotifyOnNewMemberCreatedHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using DevBetterWeb.Core; | ||
using DevBetterWeb.Core.Events; | ||
using DevBetterWeb.Core.Interfaces; | ||
using DevBetterWeb.Web.Areas.Identity.Data; | ||
using Microsoft.AspNetCore.Identity; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace DevBetterWeb.Infrastructure.Services | ||
{ | ||
public class NotifyOnNewMemberCreatedHandler : IHandle<NewMemberCreatedEvent> | ||
{ | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
private readonly IEmailService _emailService; | ||
|
||
public NotifyOnNewMemberCreatedHandler(UserManager<ApplicationUser> userManager, | ||
IEmailService emailService) | ||
{ | ||
_userManager = userManager; | ||
_emailService = emailService; | ||
} | ||
public async Task Handle(NewMemberCreatedEvent domainEvent) | ||
{ | ||
var usersInAdminRole = await _userManager.GetUsersInRoleAsync(AuthConstants.Roles.ADMINISTRATORS); | ||
|
||
foreach(var emailAddress in usersInAdminRole.Select(user => user.Email)) | ||
{ | ||
string subject = $"[devBetter] New Member {domainEvent.Member.UserFullName()}"; | ||
string message = "A new Member has signed up and added their membership profile."; // TODO: Add more member details to email | ||
await _emailService.SendEmailAsync(emailAddress, subject, message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
using DevBetterWeb.Core.Interfaces; | ||
using DevBetterWeb.Core.SharedKernel; | ||
using System.Threading.Tasks; | ||
|
||
namespace DevBetterWeb.Tests | ||
{ | ||
public class NoOpDomainEventDispatcher : IDomainEventDispatcher | ||
{ | ||
public void Dispatch<TEvent>(TEvent domainEvent) where TEvent : BaseDomainEvent | ||
public Task Dispatch(BaseDomainEvent domainEvent) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |