Пример #1
0
 public async Task <IActionResult> Update([FromBody] CreateUpdateCommentViewModel viewModel)
 {
     return(await Validation_EmailConfirmation_ModelState(User, ModelState, (user) => {
         if (commentBehaviour.TheOwnerIs(viewModel.CommentId ?? -1, user.Id))
         {
             commentBehaviour.Update(viewModel);
             return StatusCode(201);
         }
         return Unauthorized("Not owning this entity.");
     }));
 }
Пример #2
0
 public async Task <IActionResult> Create([FromBody] CreateUpdateCommentViewModel viewModel)
 {
     return(await Validation_EmailConfirmation_ModelState(User, ModelState, (user) => {
         viewModel.UserId = user.Id;
         if (commentBehaviour.Create(viewModel))
         {
             return StatusCode(201);
         }
         return Conflict("Could not create comment.");
     }));
 }
Пример #3
0
        public bool Update(CreateUpdateCommentViewModel model)
        {
            if (string.IsNullOrEmpty(model.BodyText))
            {
                return(false);
            }
            var comment = model.AsComment();

            comment.CreationTime = DateTime.UtcNow;
            return(commentRepository.Update(comment));
        }
Пример #4
0
        public static CreateUpdateCommentViewModel AsCreateUpdateCommentViewModel(this Comment comment)
        {
            var viewModel = new CreateUpdateCommentViewModel
            {
                UserId       = comment.UserId,
                CommentId    = comment.CommentId,
                BodyText     = comment.BodyText,
                CreationTime = comment.CreationTime.ToString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'"),
                PostId       = comment.PostId,
                ParentId     = comment.ParentId
            };

            return(viewModel);
        }
Пример #5
0
        public static Comment AsComment(this CreateUpdateCommentViewModel viewModel)
        {
            var comment = new Comment
            {
                UserId    = viewModel.UserId,
                CommentId = viewModel.CommentId ?? 0,
                BodyText  = viewModel.BodyText,
                //CreationTime = viewModel.CreationTime,
                PostId   = viewModel.PostId ?? 0,
                ParentId = viewModel.ParentId
            };

            return(comment);
        }
Пример #6
0
 public bool Create(CreateUpdateCommentViewModel model)
 {
     try
     {
         var comment = new Comment();
         comment.CreationTime = DateTime.UtcNow;
         comment           = model.AsComment();
         comment.CommentId = 0;
         commentRepository.Add(comment);
         return(true);
     }
     catch
     {
         return(false);
     }
 }