public HttpResponseMessage EditComment(string sessionKey, int id, CommentModel comment) { User user = null; try { user = this.usersRepository.GetBySessionKey(sessionKey); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid user!")); } if (id != comment.ID) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } Comment updatedComment = null; try { updatedComment = CommentsMapper.ToCommentEntity(comment, usersRepository); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid comment model provided!")); } this.commentsRepository.Update(id, updatedComment); return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage AddComment(string sessionKey, CommentModel comment) { User user = null; try { user = this.usersRepository.GetBySessionKey(sessionKey); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid user!")); } comment.Author = user.Nickname; Comment commentEntity = null; try { commentEntity = CommentsMapper.ToCommentEntity(comment, usersRepository); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid news article model provided!")); } comment.ID = commentEntity.ID; this.commentsRepository.Add(commentEntity); return(Request.CreateResponse(HttpStatusCode.Created, comment)); }