BloggingSystem.Services.Controllers.PostsController.Comment C# (CSharp) Method

Comment() private method

private Comment ( int postID, [ comment, [ sessionKey ) : HttpResponseMessage
postID int
comment [
sessionKey [
return System.Net.Http.HttpResponseMessage
        public HttpResponseMessage Comment(int postID, [FromBody]CommentModel comment,
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            HttpResponseMessage httpResponse = this.PerformOperation(() =>
            {
                UserValidator.ValidateSessionKey(sessionKey);

                var context = new BloggingSystemContext();
                using (context)
                {
                    var loggedUserEntity = context.Users.FirstOrDefault<User>(u => u.SessionKey == sessionKey);
                    if (loggedUserEntity == null)
                    {
                        throw new InvalidOperationException("Invalid user or pasword!");
                    }

                    var existingPostEntity = context.Posts.Find(postID);
                    if (existingPostEntity == null)
                    {
                        return this.Request.CreateErrorResponse(
                            HttpStatusCode.NotFound, "Post with provided ID not found!");
                    }

                    existingPostEntity.Comments.Add(CommentsMapper.ToEntity(comment, loggedUserEntity));
                    context.SaveChanges();

                    var response = this.Request.CreateResponse(HttpStatusCode.OK);
                    return response;
                }
            });

            return httpResponse;
        }