public IActionResult PartiallyUpdateComment(string id, [FromBody] JsonPatchDocument <Comment> jsonPatch) { Comment toPatch = commentRepo.GetSingle(commentRepo.guidColumnName, id); jsonPatch.ApplyTo(toPatch, ModelState); TryValidateModel(ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var model = new { patchedUser = toPatch, patchOperations = jsonPatch }; if (jsonPatch.Operations.Count > 1) { if (!commentRepo.Update(toPatch, this.commentRepo.guidColumnName, id)) { return(new StatusCodeResult(500)); } } else { string column = jsonPatch.Operations.Single().path.Substring(1); string value = jsonPatch.Operations.Single().value.ToString(); if (!commentRepo.Update(column, value, this.commentRepo.guidColumnName, id)) { return(new StatusCodeResult(500)); } } /* * How to send patch from body * [ * { * "op": "replace", * "path": "/<property name>", * "value": "<property value>" * }, * { * "op": "replace", * "path": "/<property name>", * "value": "<property value>" * }, * ] */ return(Ok(model)); }
public ActionResult Edit(int id) { var comment = repository.Get(id); if (comment == null) { return(HttpNotFound()); } else { repository.Update(comment); repository.SaveChanges(); return(RedirectToAction("List")); } }
public async Task <IActionResult> PutComment(int id, Comment comment) { if (id != comment.Id) { return(BadRequest()); } try { await _repository.Update(comment); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult Put([FromBody] Comment com, int id, int id2) { com.CommentId = id2; com.PostId = id; commentRepository.Update(com); return(Ok(com)); }
public ActionResult Reply(string subject, string comment, string datasetId, string parentType, string container, string origRowKey) { var result = new Comment { Subject = subject, Body = comment, Posted = DateTime.Now, Type = "General Comment (no reply required)", Status = "N/A", Notify = false, ParentName = datasetId, ParentType = parentType, Author = User.Identity.Name, ParentContainer = container }; CommentRepository.AddComment(result); Comment original = CommentRepository.GetComment(origRowKey); original.Status = "Replied"; CommentRepository.Update(original); return(Json("Replied", JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteComment(int id) { bool result = false; int userId = ((Business.Services.CustomPrincipal)User).UserId; CommentRepository comment = new CommentRepository(SessionCustom); comment.Entity.CommentId = id; comment.LoadByKey(); if (comment.Entity.ContentId.HasValue) { ContentRepository content = new ContentRepository(SessionCustom); content.Entity.ContentId = comment.Entity.ContentId; content.LoadByKey(); if ((Utils.IsBlogAdmin(userId) && content.Entity.UserId == userId) || comment.Entity.UserId == userId) { comment.Entity.Active = false; comment.Update(); result = true; } } return(this.Json(new { result = result })); }
public JsonResult Borrar(int commentId) { bool result = false; int userId = ((CustomPrincipal)User).UserId; CommentRepository comment = new CommentRepository(SessionCustom); comment.Entity.CommentId = commentId; comment.LoadByKey(); IdeaRepository idea = new IdeaRepository(SessionCustom); idea.Entity.IdeaId = comment.Entity.IdeaId; idea.LoadByKey(); if (userId == comment.Entity.UserId /*|| userId == idea.Entity.UserId*/) { comment.Entity.Active = false; comment.Update(); result = true; } return(this.Json(new { result = result })); }
public JsonResult Editar(int commentId, string text) { bool result = false; int userId = ((CustomPrincipal)User).UserId; CommentRepository comment = new CommentRepository(SessionCustom); comment.Entity.CommentId = commentId; comment.LoadByKey(); if (userId == comment.Entity.UserId || ((CustomPrincipal)User).IsFrontEndAdmin) { SessionCustom.Begin(); comment.Entity.Text = text; comment.Update(); result = true; SessionCustom.Commit(); } return(this.Json(new { result = result })); }
public void UpdateTest() { var commentRepository = new CommentRepository(new InMemoryDbContextFactory()); var userRepository = new UserRepository(new InMemoryDbContextFactory()); var author = new UserDetailModel(); var dbAuthor = userRepository.Insert(author); var commentOld = new CommentDetailModel() { Timestamp = DateTime.Now, Author = dbAuthor, Content = "Mamka mi zjedla rezen.", }; var commentNew = new CommentDetailModel() { Timestamp = DateTime.Now, Content = "Ocko mi zjedol rezen nakoniec.", Author = dbAuthor }; var commentDetail = commentRepository.Insert(commentNew); commentRepository.Update(commentNew); var commentDatabase = commentRepository.GetById(commentDetail.Id); Assert.NotNull(commentDatabase); Assert.Equal(commentNew.Timestamp, commentDatabase.Timestamp); Assert.Equal(commentNew.Content, commentDatabase.Content); commentRepository.Remove(commentDatabase.Id); }
public async Task UpdateComment(CommentUpdateDto commentUpdate) { var comment = await _repository.GetById(commentUpdate.Id); comment.Content = commentUpdate.NewContent; comment.LastEditDate = commentUpdate.LastEditDate; await _repository.Update(comment); }
public async Task UpdateComment(int commentId, string body) { var comment = await _commentRepository.GetByIdAsync(commentId); comment.Body = body; _commentRepository.Update(comment); await _unitOfWork.Commit(); }
public IHttpActionResult Put([FromUri] int pid, [FromUri] int cid, Comment comment) { comment.PostId = pid; comment.CommentId = cid; commentRepository.Update(comment); return(Ok(comment)); }
public void CommentRepozitoryTest() { var Repository = new CommentRepository(new InMemoryDbContextFactory()); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0)); var Comment1 = new CommentModel() { Author = 1, AuthorName = "Milos Hlava", Date = new DateTime(2019, 1, 4), Id = 1, Text = "Testovaci koment" }; var Comment2 = new CommentModel() { Author = 2, AuthorName = "Jozef Hlava", Date = new DateTime(2019, 1, 5), Id = 2, Text = "Testovaci koment cislo 2" }; Repository.Create(Comment1); Repository.Create(Comment2); var ReceivedComment1 = Repository.GetById(1); var ReceivedComment2 = Repository.GetById(2); Assert.Equal(Comment1, ReceivedComment1); Assert.Equal(Comment2, ReceivedComment2); Comment1.Text = "Updatovany text"; Repository.Update(Comment1); ReceivedComment1 = Repository.GetById(1); Assert.Equal(Comment1, ReceivedComment1); List <CommentModel> ReceivedAllComments = Repository.GetAll(); var AllComments = new List <CommentModel>(); AllComments.Add(Comment1); AllComments.Add(Comment2); var Comparer = new CollectionComparer <CommentModel>(); Assert.True(Comparer.Equals(AllComments, ReceivedAllComments)); Repository.Delete(1); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(1)); Repository.Delete(2); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(2)); }
public IActionResult EditComment(Comment comment) { var currentUserProfile = GetCurrentUserProfile(); comment.UserProfileId = currentUserProfile.Id; comment.CreateDateTime = DateTime.Now; _commentRepository.Update(comment); return(Ok(comment)); }
public IActionResult Put(int id, Comment comment) { if (id != comment.Id) { return(BadRequest()); } _commentRepository.Update(comment); return(NoContent()); }
public JsonResult _UpdateComment(Comment ins) { //...Update Object ins.CommentTypeID = 0; Comment ins2 = CRep.Update(ins); //...Repopulate Grid... return(Json(new GridModel(CRep.GetAllComment()))); }
public void UpdateComment([FromBody] CommentModel value) { try { _repository.Update(value); } catch (Exception e) { } }
public async Task <ActionResult <CommentResponse> > Update(CommentRequest commentRequest) { var comment = MapRequestToModel(commentRequest); comment = await _commentRepository.Update(comment); var commentResponse = MapModelToResponse(comment); return(commentResponse); }
public JsonResult UnBlockComment(int id) { CommentRepository objcomment = new CommentRepository(this.SessionCustom); objcomment.Entity.CommentId = id; objcomment.Entity.Active = true; objcomment.Update(); this.InsertAudit("Unblocked", this.Module.Name + " -> Comment" + id); return(this.Json(new { result = true })); }
public JsonResult UpdateComment(int id, string text) { CommentRepository objcomment = new CommentRepository(this.SessionCustom); objcomment.Entity.CommentId = id; objcomment.Entity.Text = text; objcomment.Update(); this.InsertAudit("Update", this.Module.Name + " -> Comment" + id); return(this.Json(new { result = true })); }
public IActionResult Put(int id, CommentViewModel request) { if (!ModelState.IsValid) { return(BadRequest("Parametros invalidos")); } var result = _repository.Update(id, request); return(result ? (IActionResult)Ok() : NotFound()); }
public IHttpActionResult Put([FromUri] int id, [FromBody] Comment p) { if (p.ComUserID == id) { cr.Update(p); return(Ok(p)); } return(StatusCode(HttpStatusCode.Forbidden)); }
public ActionResult UpdateStatus(string rowKey, string status) { Comment original = CommentRepository.GetComment(rowKey); original.Status = status; CommentRepository.Update(original); return(Json(new StatusInfo { Status = status, Show = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult Unsubscribe(string id, string type, string user, string container, bool accept) { foreach (Comment ce in CommentRepository.GetByParentAndUser(id, container, type, user)) { if (ce.Notify) { ce.Notify = false; CommentRepository.Update(ce); } } return(Json("You successfully unsubscribed")); }
public void TestEntityUpdate() { var comment = CommentBuilder.New().Build(); var mockTeste = new Mock <IUpdateDB <Comment> >(); var commentRepository = new CommentRepository(mockTeste.Object); commentRepository.Update(comment); mockTeste.Verify(x => x.UpdateRegister(It.IsAny <Comment>())); }
public void Update_Void_ReturnChangedComment() { _comment.Id = _commentRepository.Create(_comment); var result = _commentRepository.Get(_comment.Id); AreEqualComments(result, _comment); _commentNew.Id = _comment.Id; _commentRepository.Update(_commentNew); result = _commentRepository.Get(_comment.Id); AreEqualComments(result, _commentNew); }
public CommentDetailModel Save(CommentDetailModel model) { if (model.Id == Guid.Empty) { return(repository.Add(model)); } else { repository.Update(model); return(model); } }
public IActionResult Put(int id, Comment comment) { if (id != comment.Id) { return(BadRequest()); } var currentUser = GetCurrentUser(); comment.UserId = currentUser.Id; _commentRepo.Update(comment); return(NoContent()); }
public void UpdateComment_ThrowException_WhenNullIsSupplied() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); // Act & Assert Assert.ThrowsException <ArgumentNullException>(() => commentRepository.Update(null)); }
public void Update() { // Arrange CommentRepository commentRepository = new CommentRepository(dbContext); Comment commentToUpdate = dbContext.Comments.First(); string newText = "Sets here new text for comment"; // Act commentToUpdate.Text = newText; commentRepository.Update(commentToUpdate); dbContext.SaveChanges(); // Assert Assert.AreEqual(dbContext.Comments.Find(commentToUpdate.Id).Text, newText); }
public ActionResult AddComment(string content, string userId, string ariticleId, string comment_temp) { CommentRepository cr = new CommentRepository(); UserRepository ur = new UserRepository(); string result = ""; if (comment_temp != "null") { string[] array = comment_temp.Split('#'); int id = Int32.Parse(array[0]); string firstUserId = array[1]; Comment c = cr.FindByID(id); User u = ur.FindByID(userId); User firstUser = ur.FindByID(firstUserId); c.Isleaf = 1; cr.Update(c); Comment comment = new Comment(); comment.UserId = userId; comment.AriticleId = ariticleId; comment.Content = content; comment.NickName = u.NickName; comment.FirstNickName = firstUser.NickName; comment.Pid = id; comment.Isleaf = 0; comment.CommentTime = DateTime.Now; cr.Add(comment); result = ""; result = JsonConvert.SerializeObject(comment); } else { User u = ur.FindByID(userId); Comment comment = new Comment(); comment.UserId = userId; comment.Content = content; comment.CommentTime = DateTime.Now; comment.AriticleId = ariticleId; comment.Pid = 0; comment.Isleaf = 0; comment.Level = 1; comment.NickName = u.NickName; comment.FirstNickName = null; cr.Add(comment); result = ""; result = JsonConvert.SerializeObject(comment); ; } return Content(result); }
public void UpdateIsSingular() { dbFactory.Run(db => { db.Insert(new Comment { Id = 1, Message = "Test Item" }); db.Insert(new Comment { Id = 2, Message = "Test Item 2" }); }); var repository = new CommentRepository(dbFactory, personRepository, issueRepository); repository.Update(new Comment { Id = 1, Message = "Test Edit" }); dbFactory.Run(db => { var response = db.Select<Comment>(); Assert.AreEqual(response.Count, 2); Assert.AreEqual(response.Single(x => x.Id == 1).Message, "Test Edit"); Assert.AreEqual(response.Single(x => x.Id == 2).Message, "Test Item 2"); }); }
public void UpdatePersists() { dbFactory.Run(db => db.Insert(new Comment { Id = 1, Message = "Test Item" })); var repository = new CommentRepository(dbFactory, personRepository, issueRepository); repository.Update(new Comment { Id = 1, Message = "Test Edit" }); dbFactory.Run(db => { var response = db.Select<Comment>(); Assert.AreEqual(response.Count, 1); Assert.AreEqual(response[0].Message, "Test Edit"); }); }