Example #1
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));
            }
        }
Example #2
0
        protected override ViewModel EnrichModel(ViewModel sourceModel)
        {
            UgcComments model = base.EnrichModel(sourceModel) as UgcComments;

            if (model != null)
            {
                var ugcService = new UgcService();
                var comments   = ugcService.GetComments(model.Target.PublicationId, model.Target.ItemId, false,
                                                        new int[] {}, 0, 0);
                model.Comments = CreateEntities(comments);
                return(model);
            }

            UgcPostCommentForm postForm = base.EnrichModel(sourceModel) as UgcPostCommentForm;

            if (postForm != null && MapRequestFormData(postForm) && ModelState.IsValid)
            {
                var ugcService = new UgcService();
                ugcService.PostComment(postForm.Target.PublicationId, postForm.Target.ItemId, postForm.UserName, postForm.EmailAddress, postForm.Content, postForm.ParentId, postForm.Metadata);
                return(new RedirectModel(WebRequestContext.RequestUrl));
            }

            return(sourceModel);
        }