You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
1.5 KiB

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