public HttpResponseMessage InsertOrUpdateComment(ProjectCommentModel projectComment, int projectId, int commentId = 0) { if (!ModelState.IsValid || projectId <= 0 || commentId < 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new ProjectCommentRepository()) { var httpStatusCode = HttpStatusCode.Created; //insert comment if (commentId.Equals(0)) { ProjectCommentRepository.StatusCodes hasInserted = s.InsertComment(projectComment, identity, projectId); switch (hasInserted) { //project not found to insert the comment case ProjectCommentRepository.StatusCodes.NOT_FOUND: httpStatusCode = HttpStatusCode.NotFound; break; //comment inserted ok case ProjectCommentRepository.StatusCodes.OK: httpStatusCode = HttpStatusCode.Created; break; } } //update existing comment else { ProjectCommentRepository.StatusCodes hasUpdated = s.UpdateComment(projectComment, identity, commentId); switch (hasUpdated) { //comment not found case ProjectCommentRepository.StatusCodes.NOT_FOUND: httpStatusCode = HttpStatusCode.NotFound; break; //not authorized to update this comment case ProjectCommentRepository.StatusCodes.NOT_AUTHORIZED: httpStatusCode = HttpStatusCode.MethodNotAllowed; break; //comment updated ok case ProjectCommentRepository.StatusCodes.OK: httpStatusCode = HttpStatusCode.OK; break; } } return(Request.CreateResponse(httpStatusCode)); } }
public HttpResponseMessage DeleteComment(int projectId, int commentId) { if (projectId <= 0 || commentId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new ProjectCommentRepository()) { var httpStatusCode = HttpStatusCode.NoContent; ProjectCommentRepository.StatusCodes hasDeleted = s.DeleteComment(identity, commentId); switch (hasDeleted) { //comment not found case ProjectCommentRepository.StatusCodes.NOT_FOUND: httpStatusCode = HttpStatusCode.NotFound; break; //not authorized to delete this comment case ProjectCommentRepository.StatusCodes.NOT_AUTHORIZED: httpStatusCode = HttpStatusCode.MethodNotAllowed; break; //comment deleted ok case ProjectCommentRepository.StatusCodes.OK: httpStatusCode = HttpStatusCode.NoContent; break; } return(Request.CreateResponse(httpStatusCode)); } }