3

I am developing an ASP.NET MVC 5 application. I am using EF6 (Code First approach) to handle the data access and C#.

I have the next scenarios:

I have an Entity named Event with the following structure

public class Entity{
    public int Id{get; set;}
    public DateTime InitialDateTime{get; set;}
    public DateTime FinalDateTime{get; set;}
    public int Status {get; set;}
    // Another properties....
}

This entity has a corresponding Controller and Views in my Web application.

Users in role Manager can schedule events through the Create action of my Event Controller. Once an event is created, the status property (described as an integer value) is set to 0.

The event status must change to 1 once the InitialDateTime property equals to the current date and time. The same operation must be done with the FinalDateTime property but changing the event status to 2. This two operations must be automatic, without any interaction of the system administrator.

I have been checking FluentScheduler, it is amazing, but seems that this library works only with predefined tasks. I need schedule tasks dynamically, maybe I am wrong.

So, my question is:

How can I change the event status automatically depending on the current date and time and the given date and time intervals?

Evan
  • 115
  • 1
  • 11
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackoverflow.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders May 31 '14 at 02:37
  • Is your question "how to schedule tasks in ASP.Net" (duplicate of many "don't even try to schedule long running task in IIS/ASP.Net process" like http://stackoverflow.com/questions/6111910/asp-net-mvc2-task-scheduler?rq=1) OR "how to write code that when triggered changes fields in DB" or something else altogether? – Alexei Levenkov May 31 '14 at 02:56
  • I agree with @AlexeiLevenkov, don't try schedule this task in ASP, there are lots of other mechanism to do this, either use the DB system or create an NT service that would periodically check the table and set the appropriate values – 3dd May 31 '14 at 03:36
  • Indeed I agree with both of you. My MVC Application is just a presentation mechanism. There is not any logic or queries. I handle queries, requests and responses in another project. I considered using triggers, unfortunately EF6 does not support triggers. – Evan May 31 '14 at 04:09
  • 1
    Have you considered using a callback system to trigger your ASP.NET MVC application at exactly `InitialDateTime` and then again later at `FinalDateTime`? Take a look at [Revalee](http://revalee.sageanalytic.com). – László Koller Jun 03 '14 at 20:45
  • @László Koller i will try it as my last option :) – Evan Jun 04 '14 at 01:45
  • 1
    Possible duplicate of [how to schedule a task in MVC4 C#?](https://stackoverflow.com/questions/14620195/how-to-schedule-a-task-in-mvc4-c) – Andreas Bergström Oct 23 '17 at 11:21

1 Answers1

0

Looking at the code for FluentScheduler.Model.Schedule it looks like you should just be able to do this:

Schedule(SomeTask).ToRunOnceAt(entity.InitialDateTime);
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293