public async Task <IActionResult> UpdateComment([FromForm] UpdateCommentViewModel model) { var callerId = await _authHelper.GetCallerId(_caller); if (await _authHelper.CheckIfUserIsBanned(callerId)) { return(new BadRequestObjectResult( new { Message = "User currently bannend", StatusCodes.Status403Forbidden })); } var updateCommentObj = new UpdateComment(model.Id, model.Comment, callerId); var updatedComment = await _commentRepository.UpdateComment(updateCommentObj); if (updatedComment.Files != null && updatedComment.Files.Any()) { _uploadHelper.DeleteCommentFiles(updatedComment.Files); updatedComment.Files = await _uploadHelper.UploadFiles(model.Files, model.Id); } await _commentRepository.UpdateCommentImages(updatedComment.Files, updatedComment.Id); return(new OkObjectResult(new { updatedComment })); }
/// <summary> /// 生成更新备注信息 /// </summary> /// <param name="op">更新备注的实体对象</param> protected override void Generate(UpdateComment op) { this.AddRun(new GenerationExceptionRun { Message = $"SQLite 不支持列的修改和删除语句,请手动操作列:{op.TableName}.{op.ColumnName}。" }); }
/// <summary> /// 生成更新备注信息 /// </summary> /// <param name="op">更新备注的实体对象</param> protected override void Generate(UpdateComment op) { if (string.IsNullOrEmpty(op.ColumnName)) { this.AddRun(new SqlMigrationRun { Sql = string.Format(@"ALTER TABLE `{0}` COMMENT '{1}'", this.Prepare(op.TableName), op.Comment) }); } else { //MySql 不支持外键修改备注,所以过滤掉外键修改备注 if (string.Compare(op.ColumnName, "id", true) != 0 && string.Compare(op.TableName, "BlogUser") != 0) { this.AddRun(new SqlMigrationRun { Sql = string.Format( @"ALTER TABLE `{0}` MODIFY COLUMN `{1}` {2} COMMENT '{3}'", this.Prepare(op.TableName), this.Prepare(op.ColumnName), this.DbTypeCoverter.ConvertToDatabaseTypeName(op.ColumnDbType), op.Comment ) }); } } }
protected override void Generate(UpdateComment op) { //参考: //http://www.cnblogs.com/xdp-gacl/p/3506099.html //http://blog.sina.com.cn/s/blog_8b7263d10101d7ak.html //http://blog.sina.com.cn/s/blog_8fe8076e01019ik7.html if (string.IsNullOrEmpty(op.ColumnName)) { this.AddRun(new SafeSqlMigrationRun { Sql = string.Format(@"EXEC sys.sp_dropextendedproperty @name=N'MS_Description', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'{0}'", op.TableName) }); this.AddRun(new SqlMigrationRun { Sql = string.Format(@"EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{1}', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'{0}'", op.TableName, op.Comment) }); } else { this.AddRun(new SafeSqlMigrationRun { Sql = string.Format(@"EXEC sys.sp_dropextendedproperty @name=N'MS_Description', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'{0}', @level2type=N'COLUMN', @level2name=N'{1}'", op.TableName, op.ColumnName) }); this.AddRun(new SqlMigrationRun { Sql = string.Format(@"EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{2}', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'{0}', @level2type=N'COLUMN', @level2name=N'{1}'", op.TableName, op.ColumnName, op.Comment, op.Comment) }); } }
public async Task UpdateCommentAsync(UpdateComment comment) { var url = ApiUrl + comment.CommentId.ToString(); var response = await _client.PostAsync(url, new StringContent( JsonConvert.SerializeObject(comment), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); }
public async Task <Comment> UpdateComment(UpdateComment input) { var comment = await _commentRepository.GetByIdAsync(input.Id); comment.Content = input.Content; await _commentRepository.UpdateAsync(comment); return(comment); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateComment model) { var entity = model.MapEntity(model, await _commentService.GetAuthorId(model.AuthorUsername)); entity.Id = id; var createdResult = await _commentService.UpdateCommentAsync(entity); return(new JsonResult(createdResult)); }
public static d.CommentEntity ToDal(this UpdateComment comment) { return(new d.CommentEntity() { Id = comment.Id, Title = comment.Title, Content = comment.Content, Value = comment.Value }); }
public async Task <IActionResult> EditComment(UpdateComment updatecomment) { var comment = await dc.Comments.FirstOrDefaultAsync(a => a.Id == updatecomment.Id); comment.comment = updatecomment.newComment; dc.Comments.Update(comment); await dc.SaveChangesAsync(); return(Ok(comment)); }
public void CanUpdate_should_throw_exception_if_comment_not_found() { var commentId = DomainId.NewGuid(); var command = new UpdateComment { CommentId = commentId, Actor = user1 }; var events = new List <Envelope <CommentsEvent> >(); Assert.Throws <DomainObjectNotFoundException>(() => GuardComments.CanUpdate(commentsId, events, command)); }
public void WriteXmlTest() { UpdateComment target = new UpdateComment { Comment = Constants.UpdateComment_One_Comment }; string actual = LinkedIn.Tests.Utility.WriteXml(target); Assert.AreEqual(this.shareContentRequest, actual); }
public async Task <ActionResult <CommentResponse> > UpdateComment(int id, UpdateComment payload) { var result = await HandleCommentOwner(id); if (result != null) { return(result); } var comment = await _comment.UpdatePostComment(id, payload.Content, _auth.GetUser()); return(new CommentResponse(comment)); }
public string UpdateCallComment(UpdateComment updateComment) { string Message = string.Empty; try { Message = objCCInternalLayer.UpdateCallComment(updateComment); } catch (Exception ex) { throw ex; } return(Message); }
public void CanUpdate_should_not_throw_exception_if_comment_is_own_notification() { var commentId = DomainId.NewGuid(); var command = new UpdateComment { CommentId = commentId, Actor = user1, Text = "text2" }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>() }; GuardComments.CanUpdate(command, user1.Identifier, events); }
public void CanUpdate_should_throw_exception_if_comment_from_another_user() { var commentId = DomainId.NewGuid(); var command = new UpdateComment { CommentId = commentId, Actor = user2, Text = "text2" }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>() }; Assert.Throws <DomainException>(() => GuardComments.CanUpdate(commentsId, events, command)); }
public void CanUpdate_should_not_throw_exception_if_comment_from_same_user() { var commentId = DomainId.NewGuid(); var command = new UpdateComment { CommentId = commentId, Actor = user1, Text = "text2" }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>() }; GuardComments.CanUpdate(commentsId, events, command); }
public async Task Delete_should_create_events_and_update_state() { var createCommand = new CreateComment { Text = "text1" }; var updateCommand = new UpdateComment { Text = "text2", CommentId = createCommand.CommentId }; var deleteCommand = new DeleteComment { CommentId = createCommand.CommentId }; await sut.ExecuteAsync(CreateCommentsCommand(createCommand)); await sut.ExecuteAsync(CreateCommentsCommand(updateCommand)); var result = await sut.ExecuteAsync(CreateCommentsCommand(deleteCommand)); result.ShouldBeEquivalent(new EntitySavedResult(2)); sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult { Version = 2 }); sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult { DeletedComments = new List <Guid> { deleteCommand.CommentId }, Version = 2 }); sut.GetCommentsAsync(1).Result.Should().BeEquivalentTo(new CommentsResult { DeletedComments = new List <Guid> { deleteCommand.CommentId }, Version = 2 }); LastEvents .ShouldHaveSameEvents( CreateCommentsEvent(new CommentDeleted { CommentId = createCommand.CommentId }) ); }
public void CanUpdate_should_throw_exception_if_text_not_defined() { var commentId = DomainId.NewGuid(); var command = new UpdateComment { CommentId = commentId, Actor = user1 }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>() }; ValidationAssert.Throws(() => GuardComments.CanUpdate(commentsId, events, command), new ValidationError("Text is required.", "Text")); }
protected override void Generate(UpdateComment op) { if (string.IsNullOrEmpty(op.ColumnName)) { this.AddRun(new SqlMigrationRun { Sql = string.Format(@"COMMENT ON TABLE ""{0}"" IS '{1}'", this.Prepare(op.TableName), op.Comment) }); } else { this.AddRun(new SqlMigrationRun { Sql = string.Format(@"COMMENT ON COLUMN ""{0}"".""{1}"" IS '{2}'", this.Prepare(op.TableName), this.Prepare(op.ColumnName), op.Comment) }); } }
// Map a UpdateComment object to a DAL.Comment object public static Comment MapComment(UpdateComment uc) { try { var c = new Comment() { Comment1 = uc.Comment, Modified = uc.Modified, ID = uc.CommentId }; logger.Info("Comment " + uc.CommentId + " updated succesfully."); return(c); } catch (Exception ex) { logger.Error(ex, "Attempt to update comment " + uc.CommentId + " failed: " + ex.Message); return(null); // return nothing to the caller } }
public static void CanUpdate(UpdateComment command, string commentsId, List <Envelope <CommentsEvent> > events) { Guard.NotNull(command, nameof(command)); var comment = FindComment(events, command.CommentId); if (!string.Equals(commentsId, command.Actor.Identifier) && !comment.Payload.Actor.Equals(command.Actor)) { throw new DomainException(T.Get("comments.notUserComment")); } Validate.It(e => { if (string.IsNullOrWhiteSpace(command.Text)) { e(Not.Defined(nameof(command.Text)), nameof(command.Text)); } }); }
public void CanUpdate_should_throw_exception_if_comment_deleted_found() { var commentId = DomainId.NewGuid(); var command = new UpdateComment { CommentId = commentId, Actor = user1 }; var events = new List <Envelope <CommentsEvent> > { Envelope.Create <CommentsEvent>(new CommentCreated { CommentId = commentId, Actor = user1 }).To <CommentsEvent>(), Envelope.Create <CommentsEvent>(new CommentDeleted { CommentId = commentId }).To <CommentsEvent>() }; Assert.Throws <DomainObjectNotFoundException>(() => GuardComments.CanUpdate(commentsId, events, command)); }
public static void CanUpdate(List <Envelope <CommentsEvent> > events, UpdateComment command) { Guard.NotNull(command); var comment = FindComment(events, command.CommentId); if (!comment.Payload.Actor.Equals(command.Actor)) { throw new DomainException("Comment is created by another actor."); } Validate.It(() => "Cannot update comment.", e => { if (string.IsNullOrWhiteSpace(command.Text)) { e(Not.Defined("Text"), nameof(command.Text)); } }); }
public async Task <Comment> UpdateComment(UpdateComment updateComment) { var query = $@"UPDATE juniro.comments SET Message = '{updateComment.Comment}' WHERE Id = {updateComment.Id} AND UserId = '{updateComment.UserId}';"; var result = new Comment(); using (var connection = new MySqlConnection(_connectionString)) { var affectedRows = await connection.ExecuteAsync(query, new { updateComment }); if (affectedRows > 0) { result = await GetSingleComment(updateComment.Id, connection, updateComment.UserId); } } return(result); }
public async Task <object> Patch(UpdateComment request) { try { var comment = await _commentsRepository.UpdateCommentAsync(request.Id, request.Comment.Email, request.Comment.UpdatedComment); return(new UpdateCommentResponse { Comment = comment }); } catch (Exception ex) { return(new GetCommentsResponse { Comments = null, ResponseStatus = GetResponseStatus(ex) }); } }
public async Task Update_should_create_events_and_update_state() { var createCommand = new CreateComment { Text = "text1" }; var updateCommand = new UpdateComment { Text = "text2", CommentId = createCommand.CommentId }; await sut.ExecuteAsync(CreateCommentsCommand(createCommand)); var result = await sut.ExecuteAsync(CreateCommentsCommand(updateCommand)); result.ShouldBeEquivalent(new EntitySavedResult(1)); sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult { CreatedComments = new List <Comment> { new Comment(createCommand.CommentId, LastEvents.ElementAt(0).Headers.Timestamp(), createCommand.Actor, "text2") }, Version = 1 }); sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult { UpdatedComments = new List <Comment> { new Comment(createCommand.CommentId, LastEvents.ElementAt(0).Headers.Timestamp(), createCommand.Actor, "text2") }, Version = 1 }); LastEvents .ShouldHaveSameEvents( CreateCommentsEvent(new CommentUpdated { CommentId = createCommand.CommentId, Text = updateCommand.Text }) ); }
public void ReadXmlTest() { UpdateComment target = new UpdateComment(); UpdateComment expected = new UpdateComment { SequenceNumber = Constants.UpdateComment_One_SequenceNumber, Comment = Constants.UpdateComment_One_Comment, Person = new Person { Id = Constants.Person_One_Id, FirstName = Constants.Person_One_FirstName, LastName = Constants.Person_One_LastName, Headline = Constants.Person_One_Headline, ApiStandardProfileRequest = new ApiRequest { Url = Constants.ApiRequest_One_Url, Headers = new Collection <HttpHeader> { new HttpHeader { Name = Constants.HttpHeader_Name, Value = Constants.HttpHeader_Value } } }, SiteStandardProfileUrl = new SiteRequest { Url = Constants.SiteRequest_One_Url } } }; XmlReader reader = XmlTextReader.Create(new StringReader(shareContentResponse)); target.ReadXml(reader); Assert.AreEqual(expected.SequenceNumber, target.SequenceNumber); Assert.AreEqual(expected.Comment, target.Comment); Assert.AreEqual(expected.Person.Id, target.Person.Id); }
public async Task Update_should_create_events() { await ExecuteCreateAsync(); var updateCommand = new UpdateComment { Text = "text2" }; var result = await sut.ExecuteAsync(CreateCommentsCommand(updateCommand)); result.ShouldBeEquivalent((object)new EntitySavedResult(1)); sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult { CreatedComments = new List <Comment> { new Comment(commentId, GetTime(), updateCommand.Actor, "text2") }, Version = 1 }); sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult { UpdatedComments = new List <Comment> { new Comment(commentId, GetTime(), updateCommand.Actor, "text2") }, Version = 1 }); LastEvents .ShouldHaveSameEvents( CreateCommentsEvent(new CommentUpdated { Text = updateCommand.Text }) ); }
public IHttpActionResult Comments(UpdateComment uc) { try { if (!ModelState.IsValid) { return(BadRequest("Passed information isn't valid.")); } DataAccess da = new DataAccess(); if (da.UpdateComment(Mapper.MapComment(uc))) { logger.Info("Comment " + uc.CommentId + " was updated."); return(Ok()); } return(BadRequest("Failed to update the comment.")); } catch (Exception ex) { logger.Error(ex, "Attempt to update comment " + uc.CommentId + " failed: " + ex.Message); return(BadRequest("Something went wrong processing the request.")); } }
public async Task <bool> UpdateReviewComment(int id, UpdateComment comment) { bool commentUpdated = false; try { var connectionString = _config.GetConnectionString("DbConnection"); string query = "update tbl_Review set rating = " + comment.rating + ", Comment = '" + comment.comment + "' where id = " + id + ";"; using (var connection = new SqlConnection(connectionString)) { var affectedRows = await connection.ExecuteAsync(query); if (affectedRows > 0) { commentUpdated = true; } } } catch (Exception ex) { } return(commentUpdated); }