Created
December 19, 2018 03:09
-
-
Save ngohungphuc/1fe320aae7b1549c3c2ac0253d268415 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System.Threading.Tasks; | |
namespace AwesomeCMSCore.Modules.Scheduled | |
{ | |
public interface IScheduledEmailService | |
{ | |
Task SendEmailBackground(); | |
} | |
} | |
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.Threading.Tasks; | |
using AwesomeCMSCore.Modules.Email; | |
using AwesomeCMSCore.Modules.Entities.Entities; | |
using AwesomeCMSCore.Modules.Repositories; | |
using Hangfire; | |
using Microsoft.EntityFrameworkCore; | |
namespace AwesomeCMSCore.Modules.Scheduled | |
{ | |
public class ScheduledEmailService: IScheduledEmailService | |
{ | |
private readonly IEmailSender _emailSender; | |
private readonly IUnitOfWork _unitOfWork; | |
public ScheduledEmailService(IEmailSender emailSender, IUnitOfWork unitOfWork) | |
{ | |
_emailSender = emailSender; | |
_unitOfWork = unitOfWork; | |
} | |
public async Task SendEmailBackground() | |
{ | |
try | |
{ | |
var emailList = await _unitOfWork.Repository<NewsLetter>().GetAllAsync(); | |
if (emailList.Count > 0) | |
{ | |
foreach (var email in emailList) | |
{ | |
await _emailSender.SendEmailAsync(email.Email, "", null, EmailType.SubscriptionEmail); | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
throw; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment