I have an ASP.NET Core project with MySQL DB, in C# version 3.1. The site shows orders for registered users from their WooCommerce website.
for ex. When a user signs up and adds his websites URL to my website, it will show his sites orders on the Calendars page.
I use WooCommerce.net Wrapper for calling WooCommerce/WordPress REST API to get the users website orders, but the problem is that I want to check if there is a new order every 5-10 minutes for every user.
source code:
public class CalendarModel: PageModel {
public static string[] Sb {
get;
set;
}
private artistabookingdbContext _context;
private readonly RoleManager < IdentityRole > _roleManager;
private readonly UserManager < IdentityUser > _userManager;
public CalendarModel(UserManager < IdentityUser > userManager, RoleManager < IdentityRole > roleManager, artistabookingdbContext db) {
_roleManager = roleManager;
_userManager = userManager;
this._context = db;
BindDataToControl();
}
private void BindDataToControl() {
// List<AppointmentData> Appointments = await GetWooCommerceBRWAPI();
ControlSettings.Appointments = GetWooCommerceBRWAPI().Result;
}
private async Task < List < AppointmentData >> GetWooCommerceBRWAPI() {
var result = await _context.WebAPISettings.Where(param => param.Name.Equals("BRW Booking")).ToListAsync();
RestAPI rest = new RestAPI("https://artistatours.com/wp-json/wc/v3/", result[0].PublicKey, result[0].PrivateKey, false);
WCObject wc = new WCObject(rest);
var orders = await wc.Order.GetAll();
.....
}
}
How can I check new orders (from API on Calendars page) every 5-10 minutes for every user and notify each of them separately by email if there is a new one?
Note: Every user will have different website/URL and with different orders.
I read that this maybe is possible with HangFire
I’m new to ASP.NET Core and Hangfire, so it would be perfect some kind of source code with explanation.
EDIT (17.03.2024):
My idea at the start was to:
-
Create an OrdersHistory table that is connected to AspNetUsers with UserID.
-
Every time there is a new order, compares to latest user order in DB and if isn’t in the DB, notify the user by email, that there is a new order.
-
Then the user accesses the site and clicks an “Accept” button, that will save the new orders in DB, mark as “Accepted” the order on WooCommerce part.
Now I’m studying the “check every X min / user” part and how can achieve this with Hangfire (OR on SO someone mentioned the worker service).
Thanks advanced,
Steve