3

I am writing ASP.NET MVC3 application and ran into one problem. The application is a message board. Ads can be of two types: free (Priority 2) and paid (priority 1) for a period of 2 weeks. If a user publishes a paid ads, it has the highest priority and is always at the top of the message board. The problem is this: it is necessary that in 2 weeks all paid ads automatically become free, that is, their priority is changed from 1 to 2. Please tell me how to deal with this problem? I guess I need to write a procedure that will automatically run 1 time a day (at 00:00:01) and check the validity of all paid ads, and in case of excess of two weeks (14 days), to automatically change their status from 1 to 2. If so, tell me how to automatically call a procedure - through SQL (stored procedure) or directly from the controller?

This is my model file:

public class Ad
    {
        public int AdId { get; set; }
        ...
        public int AdPriority { get; set; }
    }

AdPriority can be only 1 or 2 ...

Thanks in advance for your help!

dom
  • 6,702
  • 3
  • 30
  • 35
XDev
  • 111
  • 7
  • 4
    This sounds like a Sql agent Job. http://www.quackit.com/sql_server/tutorial/sql_server_agent_jobs.cfm Hmm that's not a great link and I can't seem to find one. – asawyer Nov 09 '12 at 14:18
  • If you ever need to do it in C#, you may want to have a look at this HttpCache scheduling trick: http://stackoverflow.com/questions/733643/scheduled-jobs-in-asp-net-website-without-buying-dedicated-servers. It will run from the WebServer though, which may or may not be suitable for your case. – Allov Nov 09 '12 at 14:53
  • Does this answer your question? [how to schedule a job for sql query to run daily?](https://stackoverflow.com/questions/5471080/how-to-schedule-a-job-for-sql-query-to-run-daily) – levininja Dec 17 '19 at 17:55

0 Answers0