Пример #1
0
        public TeamPageApiController(IWorkContext workContext,
                                     ITeamPageService teamPageService,
                                     ITeamPageGroupService teamPageGroupService,
                                     ITeamPageGroupMemberService teamPageGroupMemberService,
                                     ICustomerService customerService,
                                     ICustomerProfileViewService customerProfileViewService,
                                     IDateTimeHelper dateTimeHelper,
                                     ICustomerProfileService customerProfileService,
                                     IPictureService pictureService,
                                     MediaSettings mediaSettings,
                                     mobSocialSettings mobSocialSettings)
        {
            _workContext                = workContext;
            _teamPageService            = teamPageService;
            _teamPageGroupService       = teamPageGroupService;
            _teamPageGroupMemberService = teamPageGroupMemberService;
            _customerService            = customerService;
            _dateTimeHelper             = dateTimeHelper;
            _customerProfileService     = customerProfileService;
            _pictureService             = pictureService;
            _mediaSettings              = mediaSettings;
            _mobSocialSettings          = mobSocialSettings;
            _customerProfileViewService = customerProfileViewService;

            Mapper.Initialize(cfg => cfg.CreateMap <TeamPageModel, ConfigurationModel>());
            Mapper.Initialize(cfg => cfg.CreateMap <TeamPageModel, TeamPage>());
            Mapper.Initialize(cfg => cfg.CreateMap <TeamPageGroupModel, GroupPage>());
        }
Пример #2
0
        public static CustomerProfilePublicModel ToPublicModel(this Customer customer,
                                                               IWorkContext workContext,
                                                               ICustomerProfileViewService customerProfileViewService,
                                                               ICustomerProfileService customerProfileService,
                                                               IPictureService pictureService,
                                                               MediaSettings mediaSettings,
                                                               UrlHelper url)
        {
            var customerSeName = customer.GetSeName(workContext.WorkingLanguage.Id, true, false);
            var model          = new CustomerProfilePublicModel()
            {
                CustomerId   = customer.Id,
                ViewCount    = customerProfileViewService.GetViewCount(customer.Id),
                FriendCount  = customerProfileService.GetFriendCount(customer.Id),
                CustomerName = customer.GetFullName(),
                SeName       = customerSeName,
                ProfileUrl   = url.RouteUrl("CustomerProfileUrl", new RouteValueDictionary()
                {
                    { "SeName", customerSeName }
                }),
                ProfileImageUrl =
                    pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        mediaSettings.AvatarPictureSize, true),
                CoverImageUrl =
                    pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(AdditionalCustomerAttributeNames.CoverImageId))
            };

            return(model);
        }
Пример #3
0
        public static UserSkillModel ToModel(this UserSkill userSkill, IMediaService mediaService, MediaSettings mediaSettings, IWorkContext workContext, IStoreContext storeContext,
                                             ICustomerService customerService,
                                             ICustomerProfileViewService customerProfileViewService,
                                             ICustomerProfileService customerProfileService,
                                             IPictureService pictureService,
                                             UrlHelper url, IWebHelper webHelper, bool onlySkillData = false, bool firstMediaOnly = false, bool withNextAndPreviousMedia = false, bool withSocialInfo = false)
        {
            var entityMedias = mediaService.GetEntityMedia <UserSkill>(userSkill.Id, null, count: int.MaxValue).ToList();
            var customer     = onlySkillData ? null : customerService.GetCustomerById(userSkill.UserId);
            var model        = new UserSkillModel()
            {
                DisplayOrder = userSkill.Skill.DisplayOrder,
                SkillName    = userSkill.Skill.Name,
                UserSkillId  = userSkill.Id,
                Id           = userSkill.SkillId,
                User         = onlySkillData ? null : customer.ToPublicModel(workContext, customerProfileViewService, customerProfileService, pictureService, mediaSettings, url),
                Media        =
                    entityMedias.Take(firstMediaOnly ? 1 : 15)
                    .ToList()
                    .Select(
                        x =>
                        x.ToModel <UserSkill>(userSkill.Id, mediaService, mediaSettings, workContext, storeContext, customerService, customerProfileService, customerProfileViewService, pictureService, url, webHelper))
                    .ToList(),
                TotalMediaCount   = entityMedias.Count,
                TotalPictureCount = entityMedias.Count(x => x.MediaType == MediaType.Image),
                TotalVideoCount   = entityMedias.Count(x => x.MediaType == MediaType.Video),
                ExternalUrl       = userSkill.ExternalUrl,
                Description       = userSkill.Description,
                SeName            = userSkill.Skill.GetSeName(workContext.WorkingLanguage.Id, true, false)
            };

            return(model);
        }
Пример #4
0
 public SkillController(ISkillService skillService, ICustomerService userService, IMediaService mediaService, MediaSettings mediaSettings, IUserSkillService userSkillService, ICustomerFollowService followService, ICustomerLikeService likeService, ICustomerCommentService commentService, IWorkContext workContext, ICustomerProfileService customerProfileService, ICustomerProfileViewService customerProfileViewService, IPictureService pictureService, IUrlRecordService urlRecordService, IStoreContext storeContext, IWebHelper webHelper)
 {
     _skillService               = skillService;
     _userService                = userService;
     _mediaService               = mediaService;
     _mediaSettings              = mediaSettings;
     _userSkillService           = userSkillService;
     _followService              = followService;
     _likeService                = likeService;
     _commentService             = commentService;
     _workContext                = workContext;
     _customerProfileService     = customerProfileService;
     _customerProfileViewService = customerProfileViewService;
     _pictureService             = pictureService;
     _urlRecordService           = urlRecordService;
     _storeContext               = storeContext;
     _webHelper = webHelper;
 }
 public MediaApiController(MediaService mediaService, MediaSettings mediaSettings, IMobSocialVideoProcessor videoProcessor, ICustomerService userService, ICustomerCommentService commentService, ICustomerLikeService likeService, IEntityMediaService entityMediaService, IWorkContext workContext, IStoreContext storeContext, ICustomerProfileService customerProfileService, ICustomerProfileViewService customerProfileViewService, ICustomerLikeService customerLikeService, ICustomerFollowService customerFollowService, ICustomerCommentService customerCommentService, IFriendService friendService, IPictureService pictureService, IWebHelper webHelper)
 {
     _mediaService               = mediaService;
     _mediaSettings              = mediaSettings;
     _videoProcessor             = videoProcessor;
     _userService                = userService;
     _commentService             = commentService;
     _likeService                = likeService;
     _entityMediaService         = entityMediaService;
     _workContext                = workContext;
     _storeContext               = storeContext;
     _customerProfileService     = customerProfileService;
     _customerProfileViewService = customerProfileViewService;
     _customerLikeService        = customerLikeService;
     _customerFollowService      = customerFollowService;
     _customerCommentService     = customerCommentService;
     _friendService              = friendService;
     _pictureService             = pictureService;
     _webHelper = webHelper;
 }
Пример #6
0
        public static MediaReponseModel ToModel <T>(this Media media, int entityId,
                                                    IMediaService mediaService,
                                                    MediaSettings mediaSettings,
                                                    IWorkContext workContext,
                                                    IStoreContext storeContext,
                                                    ICustomerService userService,
                                                    ICustomerProfileService customerProfileService,
                                                    ICustomerProfileViewService customerProfileViewService,
                                                    IPictureService pictureService,
                                                    UrlHelper urlHelper,
                                                    IWebHelper webHelper,
                                                    IFriendService friendService           = null,
                                                    ICustomerCommentService commentService = null,
                                                    ICustomerLikeService likeService       = null,
                                                    bool withUserInfo             = true,
                                                    bool withSocialInfo           = false,
                                                    bool withNextAndPreviousMedia = false,
                                                    bool avoidMediaTypeForNextAndPreviousMedia = false) where T : BaseEntity
        {
            var storeUrl = webHelper.GetStoreLocation();
            var model    = new MediaReponseModel()
            {
                Id             = media.Id,
                MediaType      = media.MediaType,
                Url            = media.MediaType == MediaType.Image ? mediaService.GetPictureUrl(media) : mediaService.GetVideoUrl(media),
                MimeType       = media.MimeType,
                DateCreatedUtc = media.DateCreated,
                ThumbnailUrl   = media.MediaType == MediaType.Image ? mediaService.GetPictureUrl(media) : media.ThumbnailPath.Replace("~", storeUrl)
            };

            if (withUserInfo && userService != null)
            {
                var user = userService.GetCustomerById(media.UserId);
                if (user != null)
                {
                    var dateTimeHelper = EngineContext.Current.Resolve <IDateTimeHelper>();
                    model.CreatedBy        = user.ToPublicModel(workContext, customerProfileViewService, customerProfileService, pictureService, mediaSettings, urlHelper);
                    model.DateCreatedLocal = dateTimeHelper.ConvertToUserTime(media.DateCreated, DateTimeKind.Utc);
                }
            }
            if (withSocialInfo)
            {
                if (likeService != null)
                {
                    model.TotalLikes = likeService.GetLikeCount <Media>(media.Id);
                    model.LikeStatus =
                        likeService.GetCustomerLike <Media>(workContext.CurrentCustomer.Id, media.Id) != null
                            ? 1
                            : 0;
                }

                if (commentService != null)
                {
                    model.TotalComments = commentService.GetCommentsCount(media.Id, typeof(Media).Name);
                    model.CanComment    = true; //todo: perform check if comments are enabled or user has permission to comment
                }
            }

            if (withNextAndPreviousMedia)
            {
                MediaType?mediaType = null;
                if (!avoidMediaTypeForNextAndPreviousMedia)
                {
                    mediaType = media.MediaType;
                }
                var allMedia   = mediaService.GetEntityMedia <T>(entityId, mediaType, 1, int.MaxValue).ToList();
                var mediaIndex = allMedia.FindIndex(x => x.Id == media.Id);

                model.PreviousMediaId = mediaIndex <= 0 ? 0 : allMedia[mediaIndex - 1].Id;
                model.NextMediaId     = mediaIndex < 0 || mediaIndex == allMedia.Count - 1 ? 0 : allMedia[mediaIndex + 1].Id;
            }

            model.FullyLoaded = withSocialInfo && withNextAndPreviousMedia;
            return(model);

            ;
        }
Пример #7
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);
        }