I'm working on my final project for a course named Web Applications in ASP.NET.

Basically, it's a web application for shopkeepers to manage their clients' money accounts in their stores.

In order to open an account, the shopkeeper and the other person have to agree on the length of period for the account, the interest type rate and other variables.

For example, let's suppose that a person opens an account today and in two weeks, he has to pay for all the products he has bought. If he doesn't pay that day, he's charged a late payment fee. This late payment fee is charged every day until the person cancels his debt.

It's important to mention that a person can partially or totally pay his amount due before the closing day.

Now, how can I execute that action in my web application, so that it checks after a period of time if the user has paid or not and if he hasn't, it checks daily until the user has canceled all his debts?

This is the pseudocode for the action that I want to execute:

This pseudocode can be further improved, but I think it explains what I want to achieve

if today is the closing day for a user's account
   if user's account amount is 0
      don't execute this task anymore and discard it
      charge the person a late payment fee

if today's date is greater than the closing day for a user's account
   if user's account amount is 0
      don't execute this task anymore and discard it
      charge the person a late payment fee

And also, should this action be executed on the database or the server?

I'm using Asp.Net MVC5 and IIS 10.0 for developing the web application. And for the database, I'm using SQL Server 2014.

I hope I made myself clear and if I didn't, please let me know. And by the way, English is not my mother tongue; please excuse any errors on my part.

4 Answers 4


Nothing in your requirements suggests that you need to have a batch run every day. Instead, you need to be able to compute a customer's balance at the moment it is needed: when the user requests his balance, receives an invoice, or if you wish to print collection letters.

The funny thing about computers is that they don't know what day it is. You don't need to do a computation on the day it applies to-- you can do it retroactively.

For example, if a user opened an account on January 1st, and today is February 1st, and you wish to compute their balance, you'd just need something like

public decimal GetCurrentBalance(User user)
    var balance = user.BalanceAsOfDate(user.DateAccountOpened);
    for (DateTime d = user.DateAccountOpened; d < DateTime.Today; d = d.AddDays(1))
        if (d > user.dateAccountOpened.AddDays(14))
            balance += lateFeeAmount;
    return balance;

In many situations maybe it'd be preferable to have a daily job-- e.g. if you have daily reports that sum the company's receivables-- but for your specific problem, it isn't necessary.

  • Laiv, you are mistaken. My code does not contain anything that updates state.
    – John Wu
    Jul 2, 2017 at 0:04

Programs are good doing repetitive jobs.

Instead of scheduling tasks on a precise date and moment, try scheduling 3 periodic tasks.

Task 1: Accounts about to expire

Let's say this task is executed once per hour. The task searches in the database those accounts about to expire (for instance, within 2-3 days). The owners are notified concerning to this matter at least once.

Task 2: Closing accounts

As the previous tasks, it could be executed once per hour too. The task searches accounts that expire today to close them.

Task 3: Calculate penalty

This task could be scheduled to be executed daily. It searches accounts that already expired with amounts greater than 0. It will calculate and update the penalty.

Regarding this topic, you might be interested in : batch processes and Job schedulers.

There are numerous ways for scheduling tasks. I'm a fan of the simplicity so I would suggest to look for task schedulers compatible with cron expressions.

Note: The periodicity suggested here is just for illustration, tune it up according to your preferences and needs.

  • That works, but is kind of old-style (or "last century architecture"). Modern customers would expect their account to be 100% up-to-date the moment they log into the application from their mobile. That wouldn't work with batch jobs and hourly/daily updates.
    – tofro
    Jun 30, 2017 at 16:16
  • You are making too much assumptions: modern customers, customers want modern architectures, mobile apps. OP didn't mention any of these things. I just gave some highlines for one of the many possible approaches. A easy one. I don't have all the details. I don't either know his constraints and finally, it's just a project for trainning. Anyways, feel free to elaborate your answer :-)
    – Laiv
    Jun 30, 2017 at 18:59

Scheduled Console Application execution

  1. I prefer a console application for such job because with a console application I can do custom calculation and logic. The console application can also use the Stored Procedures.
  2. Another advantage of Console Application is we can monitor log activities. If it throws any error that we can see on the console. Additionally the log can also be saved in DB, text file etc.
  3. A Console Application is independent of specific database. It can work with SQL Server, Oracle etc.

Scheduling a Console Application to execute on periodic basis on Windows Server or Windows 7/10

  1. Open Task Scheduler Application in Windows OS
  2. In Action Menu, click on create task.
  3. In Create Task Window. Set the Trigger i.e. the schedule of execution of Console Application
  4. In Same Window - set the Action i.e. the path of executable.
  5. Click OK and close window. DONE

I think a good way to do this would be on the SQL Server side. Create a JOB that runs a stored procedure (maybe every hour? day?) that goes in and checks and changes the data accordingly. The front end will end up picking the data up every time you do a service call.

  • Thanks for replying! I'd really appreciate a link for creating this stored procedure. It seems that it is what I need for my web application.
    – GianMS
    Jul 1, 2017 at 2:49
  • I think it would be best if you Google how to create them and learn how to create your own Stored Procedure. If you get stuck I'll be happy to help!
    – Og Ramos
    Jul 4, 2017 at 21:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.