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);
        }
示例#2
0
        public static SkillWithUsersModel ToSkillWithUsersModel(this Skill skill, IWorkContext workContext, IStoreContext storeContext, ICustomerService customerService, IUserSkillService userSkillService, IMediaService mediaService,
                                                                MediaSettings mediaSettings, ICustomerFollowService followService, ICustomerLikeService likeService, ICustomerCommentService commentService, ICustomerProfileService customerProfileService, ICustomerProfileViewService customerProfileViewService, IPictureService pictureService, UrlHelper urlHelper, IWebHelper webHelper)
        {
            var currentUser = workContext.CurrentCustomer;
            var model       = new SkillWithUsersModel()
            {
                Skill = skill.ToModel(workContext),
                FeaturedMediaImageUrl = skill.FeaturedImageId > 0 ? mediaService.GetPictureUrl(skill.FeaturedImageId) : ""
            };

            var perPage = 15;
            //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).ToList();

            model.UserSkills =
                userSkills.OrderBy(x => x.Id).Take(perPage).Select(
                    x =>
                    x.ToModel(mediaService, mediaSettings, workContext, storeContext, customerService,
                              customerProfileViewService, customerProfileService, pictureService, urlHelper, webHelper, 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);

            //does this user follow this skill?
            var userFollow = followService.GetCustomerFollow <Skill>(currentUser.Id, skill.Id);

            model.CanFollow     = true;
            model.FollowStatus  = userFollow == null ? 0 : 1;
            model.HasSkill      = userSkills.Any(x => x.UserId == currentUser.Id);
            model.TotalComments = commentService.GetCommentsCount(skill.Id, "skill");
            model.LikeStatus    = likeService.GetCustomerLike <Skill>(currentUser.Id, skill.Id) == null ? 0 : 1;
            model.TotalLikes    = likeService.GetLikeCount <Skill>(skill.Id);
            return(model);
        }