public ActionResult CreateProfile()
        {
            UserProfile profile = new UserProfile()
            {
                ID = WebSecurity.CurrentUserId,
                UserName = WebSecurity.CurrentUserName,
                IsAdmin = false,
            };
            _userProfileRepo.Create(profile);

            return RedirectToAction("Index", "Scoreboard");
        }
        //Verifies that the fields are valid and returns the status.
        private string commonCompleteTask(UserProfile user, Task task, string solution = null)
        {
            string status;
            if (user == null)
            { //Ensure we have a user.
                status = "User not found";
            }
            else if (task == null)
            { //Ensure we have a task.
                status = "Task not found";
            }
            else if (DateTime.Now < task.StartTime || DateTime.Now > task.EndTime)
            { //Verify that this task can be completed.
                status = "Task is not availible at this time";
            }
            else
            { //Complete the task.
                if (!string.IsNullOrEmpty(task.Solution))
                {
                    if (solution == task.Solution)
                    {
                        addTaskToUser(user, task);
                        status = "Correct!";
                    }
                    else
                    {
                        status = "Incorrect solution.";
                    }
                }
                else
                {
                    addTaskToUser(user, task);
                    status = "Task Completed";
                }
            }

            return status;
        }
        private UserDetailsViewModel createUserDetailsViewModel(UserProfile userProfile)
        {
            UserDetailsViewModel viewModel = new UserDetailsViewModel();

            viewModel.UserName = userProfile.UserName;

            int totalScore = 0;
            viewModel.Scores = new Dictionary<string, int>();
            foreach (PointType pointType in _pointTypeRepo.GetAll())
            {
                int pointScore = userProfile.ScoreFor(pointType.Name);
                viewModel.Scores.Add(pointType.Name, pointScore);
                totalScore += pointScore;
            }
            viewModel.TotalScore = totalScore;

            viewModel.CompletedTask = new List<UserDetialsTaskViewModel>();
            viewModel.CompletedMilestones = new List<UserDetialsMilestoneViewModel>();
            foreach (CompletedTask task in userProfile.CompletedTask)
            {
                if (task.Task.IsMilestone)
                {
                    viewModel.CompletedMilestones.Add(new UserDetialsMilestoneViewModel()
                    {
                        TaskID = task.ID,
                        Name = task.Task.Name,
                        PointsEarned = task.AwardedPoints,
                        CompletedOn = task.CompletedDate,
                        ImgLink = task.Task.IconLink
                    });
                }
                else
                {
                    viewModel.CompletedTask.Add(new UserDetialsTaskViewModel()
                    {
                        TaskID = task.ID,
                        Name = task.Task.Name,
                        PointsEarned = task.AwardedPoints,
                        CompletedOn = task.CompletedDate
                    });
                }
            }

            viewModel.CompletedTask.Sort(delegate(UserDetialsTaskViewModel x, UserDetialsTaskViewModel y) { return x.CompletedOn.CompareTo(y.CompletedOn); });
            viewModel.CompletedMilestones.Sort(delegate(UserDetialsMilestoneViewModel x, UserDetialsMilestoneViewModel y) { return x.CompletedOn.CompareTo(y.CompletedOn); });

            return viewModel;
        }
        //Adds a task to the user.
        private void addTaskToUser(UserProfile user, Task task)
        {
            CompletedTask cTask = new CompletedTask()
            {
                Task = task,
                TaskID = task.ID,
                UserProfile = user,
                UserProfileID = user.ID,
                CompletedDate = DateTime.Now,
            };

            if (task.CompletedBy.Count < task.MaxBonusAwards)
                cTask.AwardedPoints = task.Points + task.BonusPoints;
            else
                cTask.AwardedPoints = task.Points;

            user.CompletedTask.Add(cTask);
            task.CompletedBy.Add(cTask);
            _taskRepo.Update(task);
            _userRepo.Update(user);
        }