Day Reminder Code for Asp.Net MVC

I want to create a web application in Asp.Net MVC for hotel reservation and customer management. I am having problems with one of the requirements. I want to create a code to send SMS messages to clients on their birthdays for those who want them from the hotel. I am confused that where I have to put the code for checking clients with the date of birth is the same as the Date today, so the Code receives a trigger every day at 12:00 in the morning , even if the web application does not start. Please explain where should I embed the code?

+4
source share
2 answers

There is an open source library called Quarz to help you with this.

There is a very good Mike Brind blog article in this library . The library provides a free API that allows you to do exactly what you want.

The following code (based on the example of the specified blog article) creates an event that is called every day at 12 o’clock:

 IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
 scheduler.Start();

 IJobDetail job = JobBuilder.Create<BirthdayJob>().Build();

 ITrigger trigger = TriggerBuilder.Create()
    .WithDailyTimeIntervalSchedule
       (s =>
        s.WithIntervalInHours(24)
        .OnEveryDay()
        .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(12, 0))
        )
 .Build();

 scheduler.ScheduleJob(job, trigger);

It can run in the context of a Web site, a Windows service, or even a WinForms application (until the user closes it).

Depending on the context, you need to plan work in different places. For a website as an Application_Start () method. For the service, this will be the OnStart () method.

, "BirthdayJob", , :

public class BirthdayJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        // Check for birthdays...
    }
}

, , -:

, IIS , - . , .

- : IIS " ", , , "" → "". - . .

, , .

Quarz Windows-Service, , .

+5

-, .

, , , , , , .., .

+2

Source: https://habr.com/ru/post/1599035/


All Articles