using System;
|
|
using System.Linq;
|
|
using FluentScheduler;
|
|
|
|
namespace Sevomin.Models.Helpers.ScheduledTasks
|
|
{
|
|
public class NewApplication : ITask
|
|
{
|
|
public async void Execute()
|
|
{
|
|
var avalins = SevominDbContext.Current.DovominJobs.ToList().Where(dj => dj.ApplyDate.Date >= DateTime.UtcNow.AddDays(-2).Date).Select(a => a.Job.Avalin);
|
|
|
|
foreach (var avalin in avalins.Distinct())
|
|
{
|
|
var applies = SevominDbContext.Current.DovominJobs.ToList().Where(dj => dj.Job.AvalinId == avalin.Id && dj.ApplyDate.Date == DateTime.UtcNow.AddDays(-2).Date);
|
|
|
|
foreach (var apply in applies)
|
|
{
|
|
SevominEmailer emailer = new SevominEmailer {EmailType = EmailType.NewApplication};
|
|
emailer.Parameters.Add("avalin-name", avalin.DisplayName);
|
|
emailer.Parameters.Add("avalin-contact", string.IsNullOrWhiteSpace(apply.Job.ContactPersonName) ? "" : apply.Job.ContactPersonName);
|
|
emailer.Parameters.Add("dovomin-name", apply.Dovomin.DisplayName);
|
|
|
|
if (string.IsNullOrWhiteSpace(apply.Job.ContactPersonEMail))
|
|
await emailer.SendAsync(avalin.Email, true, false);
|
|
else
|
|
{
|
|
await emailer.SendAsync(avalin.Email, true, false);
|
|
await emailer.SendAsync(apply.Job.ContactPersonEMail, true, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|