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

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. using System;
  2. using System.Linq;
  3. using FluentScheduler;
  4. namespace Sevomin.Models.Helpers.ScheduledTasks
  5. {
  6. public class NewApplication : ITask
  7. {
  8. public async void Execute()
  9. {
  10. var avalins = SevominDbContext.Current.DovominJobs.ToList().Where(dj => dj.ApplyDate.Date >= DateTime.UtcNow.AddDays(-2).Date).Select(a => a.Job.Avalin);
  11. foreach (var avalin in avalins.Distinct())
  12. {
  13. var applies = SevominDbContext.Current.DovominJobs.ToList().Where(dj => dj.Job.AvalinId == avalin.Id && dj.ApplyDate.Date == DateTime.UtcNow.AddDays(-2).Date);
  14. foreach (var apply in applies)
  15. {
  16. SevominEmailer emailer = new SevominEmailer {EmailType = EmailType.NewApplication};
  17. emailer.Parameters.Add("avalin-name", avalin.DisplayName);
  18. emailer.Parameters.Add("avalin-contact", string.IsNullOrWhiteSpace(apply.Job.ContactPersonName) ? "" : apply.Job.ContactPersonName);
  19. emailer.Parameters.Add("dovomin-name", apply.Dovomin.DisplayName);
  20. if (string.IsNullOrWhiteSpace(apply.Job.ContactPersonEMail))
  21. await emailer.SendAsync(avalin.Email, true, false);
  22. else
  23. {
  24. await emailer.SendAsync(avalin.Email, true, false);
  25. await emailer.SendAsync(apply.Job.ContactPersonEMail, true, false);
  26. }
  27. }
  28. }
  29. }
  30. }
  31. }