public async Task <UserStatistics> UpdateStatisticsAsync(string userId, Gender gender, int?weight) { var stats = await calculationService.CalculateStatsForUserAsync(userId, gender, weight); var userStats = new UserStatistics(userId, stats.CurrentAlcLevel, stats.CurrentNightDrinks); await SaveStatisticsForUserAsync(userStats); try { if (userStats.CurrentAlcoholization > 0) { await AddStatisticHistoryAsync(new UserStatisticHistory(userId, DateTime.UtcNow, stats.CurrentAlcLevel)); } } catch (Exception ex) { logger.LogError(ex, "Failed to save history entry for user [{user}]."); } logger.LogDebug($"Successfully updated stats for user {userId}: {userStats}"); return(userStats); }