public async override void Run()
        {
            if (this.IsShuttingDown || this.Pause)
                return;

            var db = new SportsSystemDbContext();

            var participationService = new ParticipationService(db);

            var representativeUsers = await participationService.GetDeniedUsersNotification();



            //Prepare Postal classes to work outside of ASP.NET request
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines = new ViewEngineCollection();
            engines.Add(new FileSystemRazorViewEngine(viewsPath));



            var emailService = new EmailService(engines);

            foreach (var competition in representativeUsers)
            {
                var email = new DeniedUsersNotifications
                {
                    ViewName = "DeniedUsers",
                    From = "[email protected]",
                    EndDate = competition.EndDate,
                    CompetitionName = competition.CompetitionName,
                    Subject = string.Format("رفع اشکالات مشخصات وارد شده {0}", competition.CompetitionName),
                    To = competition.Email,
                    FirstName = competition.FirstName,
                    LastName = competition.LastName,
                    University = competition.University,
                    DeniedCompetitors = competition.DeniedCompetitors,
                    DeniedTechnicalStaffs = competition.DeniedTechnicalStaffs
                };

                await emailService.SendAsync(email);
            }

            db.Dispose();
        }
        public async override void Run()
        {
            if (this.IsShuttingDown || this.Pause)
                return;


            using (var db = new SportsSystemDbContext())
            {

                //Prepare Postal classes to work outside of ASP.NET request
                var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));

                var engines = new ViewEngineCollection
                {
                    new FileSystemRazorViewEngine(viewsPath)
                };

                var emailService = new EmailService(engines);

                var competitionService = new CompetitionService(db);

                var readyCompetitions = await competitionService.GetReadyCompetitionsNotificationAsync();

                foreach (var readyCompetition in readyCompetitions)
                {
                    var email = new CompetitionNotificationEmail
                    {
                        ViewName = "ReadyCompetition",
                        From = "[email protected]",
                        StartDate = readyCompetition.StartDate.Value,
                        EndDate = readyCompetition.EndDate.Value,
                        CompetitionName = readyCompetition.CompetitionName,
                        Subject = string.Format("فراخوان برای اعلام آمادگی در {0}", readyCompetition.CompetitionName),
                        SiteUrl = IaunSportsSystemApp.GetSiteRootUrl()
                    };

                    foreach (var representativeUser in readyCompetition.RepresentativeUsers)
                    {
                        email.To = representativeUser.Email;
                        email.FirstName = representativeUser.FirstName;
                        email.LastName = representativeUser.LastName;
                        email.University = representativeUser.University;
                        email.Password = EncryptionHelper.Decrypt(representativeUser.Password, EncryptionHelper.Key);
                        await emailService.SendAsync(email);
                    }

                }


                var registerCompetitions = await competitionService.GetRegisterCompetitionsNotification();

                foreach (var registerCompetition in registerCompetitions)
                {
                    var email = new CompetitionNotificationEmail
                    {
                        ViewName = "RegisterCompetition",
                        From = "[email protected]",
                        StartDate = registerCompetition.StartDate.Value,
                        EndDate = registerCompetition.EndDate.Value,
                        CompetitionName = registerCompetition.CompetitionName,
                        Subject = string.Format("فراخوان برای ثبت نام در {0}", registerCompetition.CompetitionName),
                        SiteUrl = IaunSportsSystemApp.GetSiteRootUrl()
                    };

                    foreach (var representativeUser in registerCompetition.RepresentativeUsers)
                    {
                        email.To = representativeUser.Email;
                        email.FirstName = representativeUser.FirstName;
                        email.LastName = representativeUser.LastName;
                        email.University = representativeUser.University;
                        email.Password = EncryptionHelper.Decrypt(representativeUser.Password, EncryptionHelper.Key);
                        await emailService.SendAsync(email);
                    }

                }


                var printCardCompetitions = await competitionService.GetPrintCardCompetitionsNotification();

                foreach (var printCardCompetition in printCardCompetitions)
                {
                    var email = new CompetitionNotificationEmail
                    {
                        ViewName = "PrintCardCompetition",
                        From = "[email protected]",
                        StartDate = printCardCompetition.StartDate.Value,
                        EndDate = printCardCompetition.EndDate.Value,
                        CompetitionName = printCardCompetition.CompetitionName,
                        Subject = string.Format("فراخوان برای چاپ کارت  {0}", printCardCompetition.CompetitionName),
                        SiteUrl = IaunSportsSystemApp.GetSiteRootUrl()
                    };

                    foreach (var representativeUser in printCardCompetition.RepresentativeUsers)
                    {
                        email.To = representativeUser.Email;
                        email.FirstName = representativeUser.FirstName;
                        email.LastName = representativeUser.LastName;
                        email.University = representativeUser.University;
                        email.Password = EncryptionHelper.Decrypt(representativeUser.Password, EncryptionHelper.Key);
                        await emailService.SendAsync(email);
                    }

                }

            }

        }