Пример #1
0
        // POST: api/Comments
        public async Task <string> Post(CommentDto entity)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var commentId = await CommentGenericFacade.CreateAsync(entity);

            if (commentId.Equals(0))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return($"Created Comment with id: {commentId}");
        }
Пример #2
0
        public async Task <ActionResult> AddComment(PostListModel model)
        {
            try
            {
                var newComment = new CommentDto()
                {
                    Text          = model.NewCommentText,
                    PostedAt      = DateTime.Now.ToUniversalTime(),
                    StayAnonymous = model.StayAnonymous,
                    UserId        = model.AuthenticatedUser.Id,
                    PostId        = model.PostId
                };

                await CommentGenericFacade.CreateAsync(newComment);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }