public async Task <AccessToken> AddNewToken(User user) { var clientIp = GetClientIP(); var clientUserAgent = GetClientUserAgent(); var existingToken = await FindToken(user, clientIp, clientUserAgent); if (existingToken != null) { RemoveAccessToken(existingToken); } var token = new AccessToken { Token = Guid.NewGuid().ToString(), ClientIp = clientIp, ClientUserAgent = clientUserAgent, User = user, CreatedAt = _dateTimeService.Now() }; _db.AccessTokens.Add(token); _logger.LogInformation($"AccessToken created: ClientIp='{token.ClientIp}' CreateAt='{token.CreatedAt.ToLongDateString()}'"); return(token); }
private static DateTime CurrentWeekMarker(IBudget budget) { var lastRemainder = budget.Remainders.LastOrDefault(); var now = DateTimeService.Now(); return(lastRemainder != null && lastRemainder.Date < now ? lastRemainder.Date : now); }
private BudgetWeek BindDataOf(IBudget budget) { var dataSource = new SortedDictionary <PEOrderKey, PEBudgetRow>(); var currentWeekMarker = CurrentWeekMarker(budget); BudgetWeek currentWeek = null; var lastWeekMonth = 0; foreach (var week in budget.Weeks) { if (week.Contains(currentWeekMarker)) { currentWeek = week; } if (week.Month != lastWeekMonth) { dataSource.Add( new PEOrderKey(week.FirstDay.MonthFirstDay(), WeekRowRank.MonthTitle), new PEBudgetRow { Date = week.FirstDay.ToString("MMMM") }); } dataSource.Add( new PEOrderKey(week.FirstDay, WeekRowRank.WeekTitle), new PEBudgetRow { Date = string.Format("Неделя {0:d} - {1:d}", week.FirstDay, week.LastDay), Amount = string.Format("Свободные {0}", budget.GetFreeMoney(week.FirstDay).ToString("D")), }); // todo : performance var monthlyCashStatements = budget.MonthlyCashMovements.Within(week).ToList(); AddExpenses(week, dataSource, DayRowRank.MonthlyIncome, monthlyCashStatements.Where(_ => _.Amount > 0), currentWeek, PEBudgetRow.CurrentWeekMonthlyIncome); AddExpenses(week, dataSource, DayRowRank.MonthlyExpense, monthlyCashStatements.Where(_ => _.Amount <= 0), currentWeek, PEBudgetRow.CurrentWeekMonthlyOutcome); AddTransfers(week, dataSource, DayRowRank.Income, budget.Investments.Within(week), deletionService.DeleteCashMovement, OnEditCashMovement, currentWeek, PEBudgetRow.CurrentWeekIncome); AddTransfers(week, dataSource, DayRowRank.Expense, budget.Expenses.Within(week), deletionService.DeleteCashMovement, OnEditCashMovement, currentWeek, PEBudgetRow.CurrentWeekOutcome); AddReminders(week, dataSource, DayRowRank.Remainer, budget.Remainders.Within(week), budget, deletionService.DeleteRemainder, OnEditRemainder, currentWeek, PEBudgetRow.Default); lastWeekMonth = week.Month; } view.CalculationResults.DataSource = new List <PEBudgetRow>(dataSource.Values); var monthToBalance = budget.Remainders.LastOrDefault()?.Date ?? DateTimeService.Now(); var balance = budget.MonthlyActualBalances.GetFor(monthToBalance); var nextMonth = monthToBalance.AddMonths(1); var nextMonthBalance = budget.MonthlyActualBalances.GetFor(nextMonth); view.MonthlyBalance = $"{monthToBalance:MMM}: {balance:+#;-#}, {nextMonth:MMM}: {nextMonthBalance:+#;-#}"; return(currentWeek); }
public bool HasTimeCome(DateTime dateFrom, TimeSpan schedulePeriod, string expression) { if (string.IsNullOrEmpty(expression)) { return(false); } var nextUtc = CronExpression.Parse(expression).GetNextOccurrence(dateFrom + schedulePeriod); if (!nextUtc.HasValue) { return(false); } return(nextUtc < _dateTimeService.Now()); }
private async Task <AccessToken?> FindAccessToken(string token) { var accessToken = await _db.AccessTokens .Include(t => t.User) .SingleOrDefaultAsync(t => t.Token == token); if (accessToken == null) { return(null); } if (accessToken.ExpiredAt() <= _dateTimeService.Now()) { return(null); } return(accessToken); }
private static DateTime Now() { var svc = new DateTimeService(); return(svc.Now()); }