public static ProfileViewModel CreateViewModel(UserProfile user, bool isIndex = false)
        {
            var model = new ProfileViewModel();

            model.Id = user.UserId;
            model.Name = string.Format("{0} {1}", user.FirstName, user.LastName);
            model.Email = user.Email;
            model.Skills = new List<SkillViewModel>();
            model.Jobs = new List<JobViewModel>();
            model.Educations = new List<EducationViewModel>();
            model.APIKey = user.APIKey;

            if (isIndex)
            {
                if (user.SkillVisibility == VisibilityState.Public)
                {
                    model.Skills = user.Skills.Select(s => SkillViewModel.CreateViewModel(s));
                }

                if (user.JobsVisibility == VisibilityState.Public)
                {
                    model.Jobs = user.Jobs.Select(j => JobViewModel.CreateViewModel(j));
                }

                if (user.EducationVisibility == VisibilityState.Public)
                {
                    model.Educations = user.Education.Select(e => EducationViewModel.CreateViewModel(e));
                }
            }
            else
            {
                model.APIKey = string.Empty;
            }

            model.Connections = user.Followers
                .Where(e => e.Visibility == VisibilityState.Public)
                .Select(e => ProfileConnectionViewModel.CreateViewModel(e));

            model.Requests = user.Requests.Select(r => new ProfileViewModel()
            {
                Name = r.FromUserName,
                Id = r.FromUserId
            });

            return model;
        }
        private void MakeConnectState(UserProfile viewedUser, UserProfile currentUser, ProfileViewModel viewModel)
        {
            if (currentUser != null)
            {
                if (currentUser.UserId == viewedUser.UserId)
                {
                    viewModel.CanConnect = false;
                }
                else
                {
                    // check if the users are connected
                    if (currentUser.Following.Contains(viewedUser))
                    {
                        viewModel.Skills = viewModel.Skills.Select(s =>
                        {
                            if (!s.Endorsements.Where(u => u.Id == currentUser.UserId).Any())
                            {
                                s.CanBeEndorsed = true;
                            }
                            else
                            {
                                s.AlreadyEndorsed = true;
                            }

                            return s;
                        });
                    }
                    else
                    {
                        // check if connection hasn't already been requested
                        if (!db.Requests.Where(r =>
                            (r.FromUserId == currentUser.UserId && r.UserId == viewedUser.UserId) ||
                            (r.FromUserId == viewedUser.UserId && r.UserId == currentUser.UserId)
                            ).Any())
                        {
                            viewModel.CanConnect = true;
                        }
                    }
                }
            }
        }