public JsonResult Comment(int topic, string comment, string email, string name) { if (topic == 0) { return Json(new { status = HttpStatusCode.BadRequest}); } var cTopic = dataItemService.GetDataItem(topic); if (cTopic == null) { return Json(new { status = HttpStatusCode.NotFound }); } if (String.IsNullOrEmpty(comment) || String.IsNullOrEmpty(email) || String.IsNullOrEmpty(name)) { return Json(new { status = HttpStatusCode.NoContent }); } Comment commentTopic = new Comment { Content = comment, Name = name, Email = email, ComemmentTime = DateTime.Now, DataItemID = topic }; dataItemService.CreateComment(commentTopic); dataItemService.SaveDataItem(); var jsonData = new { status = HttpStatusCode.OK, data = new { Id = commentTopic.ID, Content = commentTopic.Content, Name = commentTopic.Name, Email = commentTopic.Email, ComemmentTime = commentTopic.ComemmentTime.ToString(), DataItemID = commentTopic.DataItemID } }; return Json(jsonData); }
public void DeleteComment(Comment comment) { this.context.Comments.Remove(comment); }
public void CreateComment(Comment comment) { this.context.Comments.Add(comment); }