public static SkillWithUsersModel ToSkillWithUsersModel(this Skill skill, IUserSkillService userSkillService, IMediaService mediaService,
                                                                MediaSettings mediaSettings, GeneralSettings generalSettings, SkillSettings skillSettings, IFollowService followService, ILikeService likeService, ICommentService commentService)
        {
            var currentUser = ApplicationContext.Current.CurrentUser;
            var model       = new SkillWithUsersModel()
            {
                Skill = skill.ToModel(),
                FeaturedMediaImageUrl = skill.FeaturedImageId > 0 ? mediaService.GetPictureUrl(skill.FeaturedImageId) : mediaSettings.DefaultSkillCoverUrl
            };

            var perPage = skillSettings.NumberOfUsersPerPageOnSinglePage;
            //by default we'll send data for 15 users. rest can be queried with paginated request
            //todo: make this thing configurable to set number of users to return with this response
            var userSkills = userSkillService.Get(x => x.SkillId == skill.Id, page: 1, count: perPage, earlyLoad: x => x.User).ToList();

            model.UserSkills =
                userSkills.Select(x => x.ToModel(mediaService, mediaSettings, generalSettings, false, true, true, false)).ToList();

            model.CurrentPage   = 1;
            model.UsersPerPage  = perPage;
            model.TotalUsers    = userSkillService.Count(x => x.SkillId == skill.Id);
            model.FollowerCount = followService.GetFollowerCount <Skill>(skill.Id);

            if (currentUser != null)
            {
                //does this user follow this skill?
                var userFollow = followService.GetCustomerFollow <Skill>(currentUser.Id, skill.Id);
                model.CanFollow    = currentUser.Id != skill.UserId;
                model.FollowStatus = userFollow == null ? 0 : 1;

                model.LikeStatus = likeService.GetCustomerLike <Skill>(currentUser.Id, skill.Id) == null ? 0 : 1;

                model.HasSkill = userSkills.Any(x => x.UserId == currentUser.Id);
            }


            model.TotalComments = commentService.GetCommentsCount(skill.Id, "skill");

            model.TotalLikes = likeService.GetLikeCount <Skill>(skill.Id);

            return(model);
        }
        public static UserResponseModel ToModel(this User user, IMediaService mediaService, MediaSettings mediaSettings, IFollowService followService = null, IFriendService friendService = null, INotificationService notificationService = null)
        {
            var currentUser = ApplicationContext.Current.CurrentUser;
            var model       = new UserResponseModel()
            {
                Id               = user.Id,
                FirstName        = user.FirstName,
                LastName         = user.LastName,
                Name             = user.Name,
                DateCreatedUtc   = user.DateCreated,
                DateCreatedLocal = DateTimeHelper.GetDateInUserTimeZone(user.DateCreated, DateTimeKind.Utc, user),
                UserName         = user.UserName,
                CoverImageUrl    = mediaService.GetPictureUrl(user.GetPropertyValueAs <int>(PropertyNames.DefaultCoverId), PictureSizeNames.MediumCover, true),
                ProfileImageUrl  = mediaService.GetPictureUrl(user.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId), PictureSizeNames.MediumProfileImage, true),
                Active           = user.Active,
                Educations       = user.Educations?.Select(x => x.ToModel(mediaService)).ToList(),
                SeName           = user.GetPermalink()?.Slug
            };

            //TODO: Put capability check instead of administration check, that'd be more scalable
            if (currentUser.IsAdministrator() && user.LastLoginDate.HasValue)
            {
                model.LastLoginDateUtc   = user.LastLoginDate;
                model.LastLoginDateLocal = DateTimeHelper.GetDateInUserTimeZone(user.LastLoginDate.Value,
                                                                                DateTimeKind.Utc, user);
            }
            if (followService != null)
            {
                model.FollowerCount  = followService.GetFollowerCount <User>(user.Id);
                model.FollowingCount = followService.Count(x => x.UserId == user.Id);
                model.CanFollow      = currentUser != null && currentUser.Id != user.Id; //todo: Check if the current user can be followed or not according to user's personalized setting (to be implementedas well)
                if (model.CanFollow)
                {
                    model.FollowStatus = followService.GetCustomerFollow <User>(currentUser.Id, user.Id) == null ? 0 : 1;
                }
            }

            if (friendService != null)
            {
                model.FriendCount =
                    friendService.Count(x => x.Confirmed && (x.FromCustomerId == user.Id || x.ToCustomerId == user.Id));
                model.FriendStatus = currentUser != null?friendService.GetFriendStatus(currentUser.Id, user.Id) : FriendStatus.None;
            }

            if (!string.IsNullOrEmpty(model.CoverImageUrl) && !string.IsNullOrEmpty(model.ProfileImageUrl))
            {
                return(model);
            }

            if (string.IsNullOrEmpty(model.CoverImageUrl))
            {
                model.CoverImageUrl = mediaSettings.DefaultUserProfileCoverUrl;
            }
            if (string.IsNullOrEmpty(model.ProfileImageUrl))
            {
                model.ProfileImageUrl = mediaSettings.DefaultUserProfileImageUrl;
            }

            //we can send notifications as well if it's a user asking for his own details
            if (currentUser != null && currentUser.Id == user.Id && notificationService != null)
            {
                var now            = DateTime.UtcNow;
                var qNotifications =
                    notificationService.Get(x => x.UserId == currentUser.Id && x.PublishDateTime <= now,
                                            x => new { x.Id }, false, earlyLoad: x => x.NotificationEvent);

                var unreadCount   = qNotifications.Count(x => !x.IsRead);
                var notifications = qNotifications.Take(15).ToList();
                model.Notifications           = notifications.Select(x => x.ToModel()).ToList();
                model.UnreadNotificationCount = unreadCount;
            }

            //check if user is online or not
            model.IsOnline = true;
            return(model);
        }