Example #1
0
        private static Dictionary <string, string> CreateMetadata(PostedComment posted, bool escape)
        {
            string pubTitle  = posted.PublicationTitle;
            string pubUrl    = posted.PublicationUrl;
            string itemTitle = posted.PageTitle;
            string pageUrl   = posted.PageUrl;
            string lang      = posted.Language;

            if (escape)
            {
                pubTitle  = $"\"{Regex.Escape(pubTitle)}\"";
                pubUrl    = $"\"{pubUrl}\"";
                pageUrl   = $"\"{pageUrl}\"";
                itemTitle = $"\"{itemTitle}\"";
                lang      = $"\"{lang}\"";
            }

            var metadata = new Dictionary <string, string>
            {
                { "publicationTitle", pubTitle },
                { "publicationUrl", pubUrl },
                { "itemTitle", itemTitle },
                { "itemUrl", pageUrl },
                { "language", lang },
                { "status", "0" }
            };

            metadata.Add("pubIdTitleLang", $"{{\"id\":{posted.PublicationId},\"title\":\"{posted.PublicationTitle}\",\"lang\":\"{posted.Language}\"}}");
            return(metadata);
        }
Example #2
0
        protected async Task ValidPostComment()
        {
            await SubmittedComment.InvokeAsync(postedComment);

            if (PostSuccess)
            {
                postedComment = new PostedComment();
                await SelectedPageInternal(new LinkModel(1));
            }
        }
        public void PostComment(PostedCommentDTO postedCommentDTO)
        {
            var           config        = new MapperConfiguration(cfg => cfg.CreateMap <PostedCommentDTO, PostedComment>());
            var           mapper        = config.CreateMapper();
            PostedComment postedComment = mapper.Map <PostedCommentDTO, PostedComment>(postedCommentDTO);

            postedComment.CreatedOn  = DateTime.Now;
            postedComment.ModifiedOn = DateTime.Now;
            PostedCommentRepository.Add(postedComment);
        }
Example #4
0
        public async Task <CommentEntity> CreateCommentAsync(string partitionKey, PostedComment comment)
        {
            dynamic p = comment.ToExpandoObject();

            p.PartitionKey = partitionKey;
            p.Table        = await _azureStorage.GetTableReferenceAsync(LvConstants.TableNameOfComment);

            await _createCommentCommand.ExecuteAsync(p);

            return(p.Entity);
        }
Example #5
0
        public ActionResult PostComment(int?publicationId, int?pageId, bool descending = false, int[] status = null,
                                        int top = 0, int skip = 0)
        {
            try
            {
                Stream req = Request.InputStream;
                req.Seek(0, SeekOrigin.Begin);
                string        json   = new StreamReader(req).ReadToEnd();
                PostedComment posted = JsonConvert.DeserializeObject <PostedComment>(json);

                if (!posted.ParentId.HasValue || pageId == null || publicationId == null)
                {
                    return(ServerError(null));
                }

                UgcService ugc = new UgcService();
                Dictionary <string, string> metadata = CreateMetadata(posted, true);

                string userId = posted.Username;
                if (string.IsNullOrEmpty(userId))
                {
                    userId = "Anonymous";
                }

                Comment result = ugc.PostComment(posted.PublicationId.Value,
                                                 posted.PageId.Value,
                                                 userId,
                                                 posted.Email,
                                                 posted.Content,
                                                 posted.ParentId ?? 0,
                                                 metadata);

                if (result == null)
                {
                    return(ServerError(null));
                }
                result.Metadata = CreateMetadata(posted, false);
                return(new ContentResult
                {
                    ContentType = "application/json",
                    Content =
                        JsonConvert.SerializeObject(result,
                                                    new JsonSerializerSettings {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    }),
                    ContentEncoding = Encoding.UTF8
                });
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
        public void AddComment(ContentReference commentFolderReference, string name, string text, DateTime date)
        {
            PostedComment newCommentBlock = _contentRepository.GetDefault <PostedComment>(commentFolderReference);

            newCommentBlock.Text            = text;
            newCommentBlock.Date            = date;
            newCommentBlock.CommentatorName = name;
            IContent newCommentBlockInstance = newCommentBlock as IContent;

            newCommentBlockInstance.Name = name;

            _contentRepository.Save(newCommentBlockInstance, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.Publish);
        }
Example #7
0
        public async Task OnPostComment(PostedComment postedComment)
        {
            postedComment.RealEstateId = int.Parse(Id);
            NewComment = await RealEstateService.PostComment(postedComment);

            if (NewComment.IsSuccesfullCommentPost)
            {
                Totalpages = (int)Math.Ceiling((decimal)await RealEstateService.GetTotalRealEstateComments(int.Parse(Id)) / QuantityPerPAge);
                await SelectedPage(1);

                StateHasChanged();
            }
        }
        public void ReportComment(ContentReference commentReference)
        {
            if (ContentReference.IsNullOrEmpty(commentReference))
            {
                throw new NullReferenceException();
            }

            PostedComment reportedComment = _contentRepository.Get <PostedComment>(commentReference);
            var           commentToUpdate = reportedComment.CreateWritableClone() as IVersionable;

            commentToUpdate.StopPublish = DateTime.Now;

            _contentRepository.Save(
                commentToUpdate as IContent,
                EPiServer.DataAccess.SaveAction.Publish,
                EPiServer.Security.AccessLevel.Read);
        }
Example #9
0
        public async Task <IHttpActionResult> Post(string partitionKey, string rowKey, [FromBody] PostedComment comment)
        {
            comment.UserId   = User.Identity.GetUserId();
            comment.UserName = User.Identity.GetUserName();
            var entity = await _commentService.CreateCommentAsync(rowKey, comment);

            if (entity != null)
            {
                return(Created(Request.RequestUri, entity));
            }
            return(BadRequest());
        }
Example #10
0
 public async Task<CommentEntity> CreateCommentAsync(string partitionKey, PostedComment comment)
 {
     return await _commentService.CreateCommentAsync(partitionKey, comment);
 }