diff --git a/BillingService/Program.cs b/BillingService/Program.cs index 3c087ce..d7d92ab 100644 --- a/BillingService/Program.cs +++ b/BillingService/Program.cs @@ -81,23 +81,25 @@ namespace Teknik.BillingService var customers = billingService.GetCustomers(); if (customers != null) { + var customerIds = customers.Select(c => c.CustomerId).ToList(); // Find customers that aren't linked anymore - var unlinkedCustomers = db.Users.Select(u => u.BillingCustomer).Where(b => !customers.Exists(c => c.CustomerId == b.CustomerId)); + var unlinkedCustomers = db.Users.Select(u => u.BillingCustomer).Where(b => b != null && !customerIds.Contains(b.CustomerId)); foreach (var customer in unlinkedCustomers) { BillingHelper.RemoveCustomer(db, customer.CustomerId); } } - foreach (var user in db.Users) + foreach (var user in db.Users.Include(u => u.BillingCustomer)) { // Only set/reset their limits if they have a subscription or have subscribed at some point - string email = UserHelper.GetUserEmailAddress(config, user.Username); if (user.BillingCustomer != null) { // get the subscriptions for this user var subscriptions = billingService.GetSubscriptionList(user.BillingCustomer.CustomerId); var uploadPrice = subscriptions.SelectMany(s => s.Prices).FirstOrDefault(p => p.ProductId == config.BillingConfig.UploadProductId); + + // Process upload subscription sync if (uploadPrice != null) { BillingHelper.SetUploadLimits(db, user, uploadPrice.Storage, uploadPrice.FileSize); @@ -106,6 +108,8 @@ namespace Teknik.BillingService { BillingHelper.SetUploadLimits(db, user, config.UploadConfig.MaxStorage, config.UploadConfig.MaxUploadFileSize); } + + // Process email subscription sync var emailPrice = subscriptions.SelectMany(s => s.Prices).FirstOrDefault(p => p.ProductId == config.BillingConfig.EmailProductId); if (emailPrice != null) { diff --git a/BillingService/Properties/launchSettings.json b/BillingService/Properties/launchSettings.json new file mode 100644 index 0000000..da735f0 --- /dev/null +++ b/BillingService/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "BillingService": { + "commandName": "Project", + "commandLineArgs": "-c C:\\Users\\chris\\Repositories\\Teknik\\Teknik\\App_Data -s" + } + } +} \ No newline at end of file diff --git a/Teknik/Areas/User/Utility/UserHelper.cs b/Teknik/Areas/User/Utility/UserHelper.cs index 3b57aa8..66bae5b 100644 --- a/Teknik/Areas/User/Utility/UserHelper.cs +++ b/Teknik/Areas/User/Utility/UserHelper.cs @@ -358,6 +358,7 @@ namespace Teknik.Areas.Users.Utility .Include(u => u.UserSettings) .Include(u => u.BlogSettings) .Include(u => u.UploadSettings) + .Include(u => u.BillingCustomer) .Where(b => b.Username == username).FirstOrDefault(); return user;