示例#1
0
        public IHttpActionResult Post(TimelinePostModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Response(new { Success = false, Message = "Invalid data" }));
            }

            //TODO: check OwnerId for valid values and store entity name accordingly, these can be customer, artist page, videobattle page etc.
            model.OwnerId         = _workContext.CurrentCustomer.Id;
            model.OwnerEntityType = TimelinePostOwnerTypeNames.Customer;

            //create new timeline post
            var post = new TimelinePost()
            {
                Message = model.Message,
                AdditionalAttributeValue = model.AdditionalAttributeValue,
                PostTypeName             = model.PostTypeName,
                DateCreated        = DateTime.UtcNow,
                DateUpdated        = DateTime.UtcNow,
                OwnerId            = model.OwnerId,
                IsSponsored        = model.IsSponsored,
                OwnerEntityType    = model.OwnerEntityType,
                LinkedToEntityName = model.LinkedToEntityName,
                LinkedToEntityId   = model.LinkedToEntityId,
                PublishDate        = model.PublishDate
            };

            //save it
            _timelineService.Insert(post);

            var postModel = PrepareTimelinePostDisplayModel(post);

            return(Response(new { Success = true, Post = postModel }));
        }
        public void Publish <T>(T entity, string postTypeName, int ownerId) where T : BaseEntity
        {
            //create new timeline post
            var post = new TimelinePost()
            {
                Message = string.Empty,
                AdditionalAttributeValue = string.Empty,
                PostTypeName             = postTypeName,
                DateCreated        = DateTime.UtcNow,
                DateUpdated        = DateTime.UtcNow,
                OwnerId            = ownerId,
                IsSponsored        = false,
                OwnerEntityType    = TimelinePostOwnerTypeNames.Customer,
                LinkedToEntityName = typeof(T).Name,
                LinkedToEntityId   = entity.Id,
                PublishDate        = DateTime.UtcNow
            };

            //save the post
            _timelineService.Insert(post);
        }
        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;

            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 = user.GetPropertyValueAs<string>(PropertyNames.DisplayName);
                postModel.OwnerImageUrl = _pictureService.GetPictureUrl(user.GetPropertyValueAs<int>(PropertyNames.DefaultPictureId));

                postModel.OwnerProfileUrl = Url.Route("CustomerProfileUrl", new RouteValueDictionary()
                    {
                        {"SeName", user.GetPermalink()}
                    });
            }
            //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;

            }

            return postModel;
        }
        public IHttpActionResult Post(TimelinePostModel model)
        {
            if (!ModelState.IsValid)
                return Response(new { Success = false, Message = "Invalid data" });

            //TODO: check OwnerId for valid values and store entity name accordingly, these can be customer, artist page, videobattle page etc.
            model.OwnerId = ApplicationContext.Current.CurrentUser.Id;
            model.OwnerEntityType = TimelinePostOwnerTypeNames.Customer;

            //create new timeline post
            var post = new TimelinePost() {
                Message = model.Message,
                AdditionalAttributeValue = model.AdditionalAttributeValue,
                PostTypeName = model.PostTypeName,
                DateCreated = DateTime.UtcNow,
                DateUpdated = DateTime.UtcNow,
                OwnerId = model.OwnerId,
                IsSponsored = model.IsSponsored,
                OwnerEntityType = model.OwnerEntityType,
                LinkedToEntityName = model.LinkedToEntityName,
                LinkedToEntityId = model.LinkedToEntityId,
                PublishDate = model.PublishDate
            };

            //save it
            _timelineService.Insert(post);

            var postModel = PrepareTimelinePostDisplayModel(post);

            return Response(new { Success = true, Post = postModel });
        }
示例#5
0
        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>(_workContext.CurrentCustomer.Id, post.Id) == null
                    ? 0
                    : 1;

            var totalComments = _customerCommentService.GetCommentsCount(post.Id, typeof(TimelinePost).Name);
            var postModel     = new TimelinePostDisplayModel()
            {
                Id                       = post.Id,
                DateCreatedUtc           = post.DateCreated,
                DateUpdatedUtc           = post.DateUpdated,
                DateCreated              = _dateTimeHelper.ConvertToUserTime(post.DateCreated, DateTimeKind.Utc),
                DateUpdated              = _dateTimeHelper.ConvertToUserTime(post.DateUpdated, DateTimeKind.Utc),
                OwnerId                  = post.OwnerId,
                OwnerEntityType          = post.OwnerEntityType,
                PostTypeName             = post.PostTypeName,
                IsSponsored              = post.IsSponsored,
                Message                  = post.Message,
                AdditionalAttributeValue = post.AdditionalAttributeValue,
                CanDelete                = post.OwnerId == _workContext.CurrentCustomer.Id || _workContext.CurrentCustomer.IsAdmin(),
                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 customer = _customerService.GetCustomerById(post.OwnerId);

                postModel.OwnerName     = customer.GetFullName();
                postModel.OwnerImageUrl =
                    _pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mediaSettings.AvatarPictureSize, true);

                postModel.OwnerProfileUrl = Url.RouteUrl("CustomerProfileUrl", new RouteValueDictionary()
                {
                    { "SeName", customer.GetSeName(_workContext.WorkingLanguage.Id, true, false) }
                });
            }
            //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.GetById(post.LinkedToEntityId);
                    if (battle == null)
                    {
                        break;
                    }
                    var battleUrl = Url.RouteUrl("VideoBattlePage",
                                                 new RouteValueDictionary()
                    {
                        { "SeName", battle.GetSeName(_workContext.WorkingLanguage.Id, true, false) }
                    });

                    //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 = "";
                    if (battle.CoverImageId.HasValue)
                    {
                        coverImageUrl = _pictureService.GetPictureUrl(battle.CoverImageId.Value);
                    }
                    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;
            }

            return(postModel);
        }
示例#6
0
        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 void ProcessInlineTags(TimelinePost post)
 {
     post.Message = Replace(post.Message, post.InlineTags);
 }