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."); })); }
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."); })); }
public bool Update(CreateUpdateCommentViewModel model) { if (string.IsNullOrEmpty(model.BodyText)) { return(false); } var comment = model.AsComment(); comment.CreationTime = DateTime.UtcNow; return(commentRepository.Update(comment)); }
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); }
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); }
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); } }