Commit fb1cf5e8 authored by Pavel Kinc's avatar Pavel Kinc
Browse files

feat: fix month period

parent 7a3a90e0
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ public class TimerService : IHostedService, IDisposable
    private Timer? _minuteTimer;
    private Timer? _dailyTimer;
    private Timer? _weeklyTimer;
    private Timer? _monthlyTimer;
    
    private readonly IServiceProvider _serviceProvider;

@@ -27,7 +26,6 @@ public class TimerService : IHostedService, IDisposable
        SetTimer(TransactionFrequency.ByMinute, TimeSpan.FromMinutes(1), new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute + 1, 0)-now);
        SetTimer(TransactionFrequency.Daily, TimeSpan.FromDays(1), new DateTime(now.Year, now.Month, now.Day + 1) - now);
        SetTimer(TransactionFrequency.Weekly, TimeSpan.FromDays(7), new DateTime(now.Year, now.Month, now.Day + 7) - now);
        SetTimer(TransactionFrequency.Monthly, TimeSpan.FromDays(30), new DateTime(now.Year, now.Month, 1).AddMonths(1) - now);

        return Task.CompletedTask;
    }
@@ -54,9 +52,6 @@ public class TimerService : IHostedService, IDisposable
            case TransactionFrequency.Weekly:
                _weeklyTimer = timer;
                break;
            case TransactionFrequency.Monthly:
                _monthlyTimer = timer;
                break;
            default:
                throw new ArgumentException("Timer frequency unknown");
        }
@@ -68,6 +63,11 @@ public class TimerService : IHostedService, IDisposable
        {
            var transactionService = scope.ServiceProvider.GetRequiredService<ITransactionService>();
            await transactionService.CopyTransactions(freq);
            // easiest way to do months (because of variable length)
            if(DateTime.Now.Day == 1 && freq == TransactionFrequency.Daily)
            {
                await transactionService.CopyTransactions(TransactionFrequency.Monthly);
            }
        }
    }

@@ -76,7 +76,6 @@ public class TimerService : IHostedService, IDisposable
        _minuteTimer?.Change(Timeout.Infinite, 0);
        _dailyTimer?.Change(Timeout.Infinite, 0);
        _weeklyTimer?.Change(Timeout.Infinite, 0);
        _monthlyTimer?.Change(Timeout.Infinite, 0);
        return Task.CompletedTask;
    }

+0 −3
Original line number Diff line number Diff line
@@ -9,17 +9,14 @@ namespace BusinessLayer.Services.Implementations
{
    public class UserService : IUserService
    {
        private readonly ManagerDbContext _dbContext;
        private readonly UserManager<User> _userManager;
        private readonly SignInManager<User> _signInManager;

        public UserService(
            ManagerDbContext dbContext,
            UserManager<User> userManager,
            SignInManager<User> signInManager
        )
        {
            _dbContext = dbContext;
            _userManager = userManager;
            _signInManager = signInManager;
        }
+0 −1
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews(options =>
{