public async Task <IHttpActionResult> AddComment(AddedComment addedComment) { if (addedComment == null) { return(NotFound()); } if (addedComment.Comment == null) { return(Json(new { status = "error", message = "No commment added!" })); } var spotz = await _db.Spotzes.FindAsync(Guid.Parse(addedComment.Id)); var newComment = new Comment { Timestamp = DateTime.Now, User = _db.Users.Find(addedComment.UserId), CommentId = Guid.NewGuid(), Text = addedComment.Comment, Spotz = spotz }; try { spotz?.Comments.Add(newComment); await _db.SaveChangesAsync(); } catch (Exception) { return(Json(new { status = "error", message = "Error creating comment!" })); } return(Json(new { status = "success", message = "Comment created!", comment = addedComment.Comment, user = newComment.User.UserName, gravatarurl = newComment.User.GetGravatarUrl() })); }
public ActionResult AddComment(AddedComment addedComment) { if (addedComment == null) { return(HttpNotFound()); } var idGuid = Guid.Parse(addedComment.Id); var spotz = _db.Spotzes.Find(idGuid); var newComment = new Comment { Timestamp = DateTime.Now, User = _db.Users.Find(Guid.Parse(addedComment.UserId)), CommentId = Guid.NewGuid(), Text = addedComment.Comment, Spotz = spotz }; spotz?.Comments.Add(newComment); return(Json(new { status = "success", message = "customer created" })); }