public static List<Challenge> GetActivePersistentChallenges(int userId = 0)
{
List<Challenge> toReturn;
using (SqlConnection connection = ConnectionManager.GetConnection())
{
var data = new ActivEarthDataProvidersDataContext(connection);
toReturn = (from c in data.ChallengeDataProviders
where c.active && c.persistent
select
new Challenge
{
ID = c.id,
Name = c.name,
Description = c.description,
Reward = c.reward,
Requirement = (float)c.requirement,
IsPersistent = c.persistent,
EndTime = c.end_time,
Duration = new TimeSpan(c.duration_days, 0, 0, 0),
StatisticBinding = (Statistic)c.statistic,
IsActive = c.active,
ImagePath = c.image_path
}).ToList();
foreach (Challenge challenge in toReturn)
{
challenge.Progress = (userId > 0 ? ChallengeManager.GetProgress(challenge.ID, userId) : 0);
challenge.FormatString = StatisticInfoDAO.GetStatisticFormatString(challenge.StatisticBinding);
}
return toReturn;
}
}