private UserCommentPublicModel PrepareCommentPublicModel(Comment comment, IEnumerable <User> users) { //get the customer var user = users.FirstOrDefault(x => x.Id == comment.UserId); if (user == null) { return(null); } var likeStatus = _customerLikeService.GetCustomerLike <Comment>(ApplicationContext.Current.CurrentUser.Id, comment.Id) == null ? 0 : 1; //and create it's response model var cModel = new UserCommentPublicModel() { EntityName = comment.EntityName, EntityId = comment.EntityId, CommentText = comment.CommentText, AdditionalData = comment.AdditionalData, Id = comment.Id, DateCreatedUtc = comment.DateCreated, DateCreated = DateTimeHelper.GetDateInUserTimeZone(comment.DateCreated, DateTimeKind.Utc, user), CanDelete = comment.UserId == ApplicationContext.Current.CurrentUser.Id || ApplicationContext.Current.CurrentUser.IsAdministrator(), IsSpam = false, //TODO: change it when spam system has been implemented LikeCount = _customerLikeService.GetLikeCount <Comment>(comment.Id), UserName = user.GetPropertyValueAs <string>(PropertyNames.DisplayName), UserProfileUrl = Url.Route("CustomerProfileUrl", new RouteValueDictionary() { { "SeName", user.GetPermalink().ToString() } }), UserProfileImageUrl = _pictureService.GetPictureUrl(user.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId), PictureSizeNames.SmallProfileImage), LikeStatus = likeStatus }; return(cModel); }
private UserCommentPublicModel PrepareCommentPublicModel(Comment comment, IEnumerable <User> users) { //get the customer var user = users.FirstOrDefault(x => x.Id == comment.UserId); if (user == null) { return(null); } //process the comment text _timelinePostProcessor.ProcessInlineTags(comment); var likeStatus = _customerLikeService.GetCustomerLike <Comment>(ApplicationContext.Current.CurrentUser.Id, comment.Id) == null ? 0 : 1; //and create it's response model var cModel = new UserCommentPublicModel() { EntityName = comment.EntityName, EntityId = comment.EntityId, CommentText = comment.CommentText, AdditionalData = comment.AdditionalData, Id = comment.Id, DateCreatedUtc = comment.DateCreated, DateCreated = DateTimeHelper.GetDateInUserTimeZone(comment.DateCreated, DateTimeKind.Utc, user), CanDelete = comment.UserId == ApplicationContext.Current.CurrentUser.Id || ApplicationContext.Current.CurrentUser.IsAdministrator(), IsSpam = false, //TODO: change it when spam system has been implemented LikeCount = _customerLikeService.GetLikeCount <Comment>(comment.Id), LikeStatus = likeStatus, User = user.ToModel(_mediaService, _mediaSettings) }; return(cModel); }
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); }
private TimelinePostDisplayModel PrepareTimelinePostDisplayModel(TimelinePost post) { //total likes for this post var totalLikes = _customerLikeService.GetLikeCount <TimelinePost>(post.Id); //the like status for current customer var likeStatus = _customerLikeService.GetCustomerLike <TimelinePost>(ApplicationContext.Current.CurrentUser.Id, post.Id) == null ? 0 : 1; //process post content to replace inline tags _timelinePostProcessor.ProcessInlineTags(post); var totalComments = _customerCommentService.GetCommentsCount(post.Id, typeof(TimelinePost).Name); var postModel = new TimelinePostDisplayModel() { Id = post.Id, DateCreatedUtc = post.DateCreated, DateUpdatedUtc = post.DateUpdated, DateCreated = DateTimeHelper.GetDateInUserTimeZone(post.DateCreated, DateTimeKind.Utc, ApplicationContext.Current.CurrentUser), DateUpdated = DateTimeHelper.GetDateInUserTimeZone(post.DateUpdated, DateTimeKind.Utc, ApplicationContext.Current.CurrentUser), OwnerId = post.OwnerId, OwnerEntityType = post.OwnerEntityType, PostTypeName = post.PostTypeName, IsSponsored = post.IsSponsored, Message = post.Message, AdditionalAttributeValue = post.AdditionalAttributeValue, CanDelete = post.OwnerId == ApplicationContext.Current.CurrentUser.Id || ApplicationContext.Current.CurrentUser.IsAdministrator(), TotalLikes = totalLikes, LikeStatus = likeStatus, TotalComments = totalComments }; if (post.OwnerEntityType == TimelinePostOwnerTypeNames.Customer) { //get the customer to retrieve info such a profile image, profile url etc. var user = _userService.Get(post.OwnerId); postModel.OwnerName = string.IsNullOrEmpty(user.Name) ? user.Email : user.Name; postModel.OwnerImageUrl = _pictureService.GetPictureUrl(user.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId), PictureSizeNames.MediumProfileImage); if (string.IsNullOrEmpty(postModel.OwnerImageUrl)) { postModel.OwnerImageUrl = _mediaSettings.DefaultUserProfileImageUrl; } } //depending on the posttype, we may need to extract additional data e.g. in case of autopublished posts, we may need to query the linked entity switch (post.PostTypeName) { case TimelineAutoPostTypeNames.VideoBattle.Publish: case TimelineAutoPostTypeNames.VideoBattle.BattleStart: case TimelineAutoPostTypeNames.VideoBattle.BattleComplete: //we need to query the video battle if (post.LinkedToEntityId != 0) { var battle = _videoBattleService.Get(post.LinkedToEntityId); if (battle == null) { break; } var battleUrl = Url.Route("VideoBattlePage", new RouteValueDictionary() { { "SeName", battle.GetPermalink() } }); //create a dynamic object for battle, we'll serialize this object to json and store as additional attribute value //todo: to see if we have some better way of doing this var coverImageUrl = ""; var coverImageId = battle.GetPropertyValueAs <int>(PropertyNames.DefaultCoverId); if (coverImageId != 0) { coverImageUrl = _pictureService.GetPictureUrl(coverImageId); } var obj = new { Name = battle.Name, Url = battleUrl, Description = battle.Description, VotingStartDate = battle.VotingStartDate, VotingEndDate = battle.VotingEndDate, CoverImageUrl = coverImageUrl, RemainingSeconds = battle.GetRemainingSeconds(), Status = battle.VideoBattleStatus.ToString() }; postModel.AdditionalAttributeValue = JsonConvert.SerializeObject(obj); } break; } //replace inline tags with html links return(postModel); }
public static MediaReponseModel ToModel<T>(this Media media, int entityId, IMediaService mediaService, MediaSettings mediaSettings = null, GeneralSettings generalSettings = null, IUserService userService = null, IFollowService followService = null, IFriendService friendService = null, ICommentService commentService = null, ILikeService likeService = null, bool withUserInfo = true, bool withSocialInfo = false, bool withNextAndPreviousMedia = false, bool avoidMediaTypeForNextAndPreviousMedia = false) where T: BaseEntity { 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, PictureSizeNames.ThumbnailImage) : WebHelper.GetUrlFromPath(media.ThumbnailPath, generalSettings?.ImageServerDomain) }; if (withUserInfo && userService != null) { var user = userService.Get(media.UserId); if (user != null) { model.CreatedBy = user.ToModel(mediaService, mediaSettings, followService, friendService); model.DateCreatedLocal = DateTimeHelper.GetDateInUserTimeZone(media.DateCreated, DateTimeKind.Utc, user); } } if (withSocialInfo) { if (likeService != null) { model.TotalLikes = likeService.GetLikeCount<Media>(media.Id); model.LikeStatus = likeService.GetCustomerLike<Media>(ApplicationContext.Current.CurrentUser.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; ; }