public User SelectUserByEmail(string email) { User user = null; using (var context = new RegistrationEntities()) { spSelectUserByEmail_Result userEF = context.spSelectUserByEmail(email).FirstOrDefault(); if (userEF != null) { user = new User(); user.ActivationDate = userEF.ActivationDate.HasValue ? userEF.ActivationDate.Value : DateTime.MinValue; user.ActivityID = userEF.ActivityID.HasValue ? userEF.ActivityID.Value : 0; user.BirthDate = userEF.BirthDate.HasValue ? userEF.BirthDate.Value : (DateTime?)null; user.CreatedDate = userEF.CreatedDate; user.CreatedBy = userEF.CreatedBy.HasValue ? userEF.CreatedBy.Value : 0; user.Description = userEF.Description; user.Email = userEF.Email; user.FacebookID = userEF.FacebookID.HasValue ? userEF.FacebookID.Value : 0; user.FirstName = userEF.FirstName; user.Gender = userEF.Gender.HasValue ? userEF.Gender.Value : 0; user.Heigh = userEF.Heigh.HasValue ? userEF.Heigh.Value : 0; user.HeighDec = userEF.HeighDec.HasValue ? userEF.HeighDec.Value : 0; user.HeighInt = userEF.HeighInt.HasValue ? userEF.HeighInt.Value : 0; user.IsApproved = userEF.IsApproved.HasValue ? userEF.IsApproved.Value : false; user.IsLockedOut = userEF.IsLockedOut.HasValue ? userEF.IsLockedOut.Value : false; user.LastLoginDate = userEF.LastLoginDate.HasValue ? userEF.LastLoginDate.Value : DateTime.MinValue; user.LastName = userEF.LastName; user.LastUpdatedBy = userEF.LastUpdatedBy.HasValue ? userEF.LastUpdatedBy.Value : 0; user.LastUpdatedDate = userEF.LastUpdatedDate.HasValue ? userEF.LastUpdatedDate.Value : DateTime.MinValue; user.Password = null; user.TerminationDate = userEF.TerminationDate.HasValue ? userEF.TerminationDate.Value : DateTime.MinValue; user.UserID = userEF.UserID; user.CurrentProgram = _workoutRepository.SelectCurrentUserProgram(user.UserID); user.IsProfileComplete = this.IsProfileComplete(user.UserID); user.Weight = userEF.Weight.HasValue ? userEF.Weight.Value : 0; user.BMI = userEF.BMI.HasValue ? userEF.BMI.Value : 0; user.Calories = userEF.Calories.HasValue ? userEF.Calories.Value : 0; if (userEF.GoalID.HasValue) { spSelectGoalByID_Result goalEF = context.spSelectGoalByID(userEF.GoalID.Value).FirstOrDefault(); Goal goal = new Goal(); goal.GoalID = goalEF.GoalID; goal.GoalName = goalEF.GoalName; goal.IsEnabled = goalEF.IsEnabled; goal.CreatedDate = goalEF.CreatedDate; user.Goal = goal; } } } return(user); }