public static Challenge GetChallengeFromChallengeId(int challengeId, int userId = 0)
{
using (SqlConnection connection = ConnectionManager.GetConnection())
{
var data = new ActivEarthDataProvidersDataContext(connection);
Challenge toReturn = (from c in data.ChallengeDataProviders
where c.id == challengeId
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
}).FirstOrDefault();
toReturn.Progress = (userId > 0 ? ChallengeManager.GetProgress(toReturn.ID, userId) : 0);
toReturn.FormatString = StatisticInfoDAO.GetStatisticFormatString(toReturn.StatisticBinding);
return toReturn;
}
}