public static User GetUserFromUserId(int userId)
{
User toReturn;
using (SqlConnection connection = ConnectionManager.GetConnection())
{
var data = new ActivEarthDataProvidersDataContext(connection);
toReturn = (from u in data.UserDataProviders
join p in data.ProfileDataProviders on u.id equals p.user_id
where u.id == userId
select
new User
{
UserName = u.user_name,
UserID = u.id,
Email = p.email,
FirstName = p.first_name,
LastName = p.last_name,
City = p.city,
State = p.state,
Gender = p.gender,
ProfileID = p.id,
Age = p.age,
Weight = p.weight,
Height = p.height,
GreenScore = p.green_score,
ActivityScore = new ActivityScore(
p.activity_score_badges,
p.activity_score_challenges,
p.activity_score_contests)
}).FirstOrDefault();
}
if (toReturn != null)
{
RecentActivityDAO.GetUserRecentActivity(toReturn);
toReturn.userPrivacySettings = PrivacySettingDAO.GetPrivacySettingFromUserId(toReturn.UserID);
List<UserStatistic> list = UserStatisticDAO.GetAllStatisticsByUserId(toReturn.UserID);
toReturn.SetStatisticsDict(
list.ToDictionary(k => k.Statistic, e => e));
}
return toReturn;
}