public IHttpActionResult GetComment(Guid id) { Comment comment = db.Comments.Find(id); if (comment == null) { return(NotFound()); } return(Ok(CommentDTO.FromEntity(comment))); }
public IHttpActionResult PostComment(Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } comment.ID = Guid.NewGuid(); comment.Added = DateTime.Now; comment.UserID = User.Identity.GetUserId(); db.Comments.Add(comment); try { db.SaveChanges(); } catch (DbUpdateException) { if (CommentExists(comment.ID)) { return(Conflict()); } else { throw; } } db = new OutOfRangeEntities(); comment = db.Comments.Find(comment.ID); Guid categoryId = Guid.Empty; if (comment.Answer != null) { categoryId = comment.Answer.Question.CategoryID; } else if (comment.Question != null) { categoryId = comment.Question.CategoryID; } PointsUtils.AddCreditsAndXP(comment.UserID, categoryId, 4, 7); return(CreatedAtRoute("DefaultApi", new { id = comment.ID }, CommentDTO.FromEntity(comment))); }