public HttpResponseMessage PostNewsArticle(string sessionKey, [FromBody] NewsArticleModel newsArticle)
        {
            User user = null;

            try
            {
                user = this.usersRepository.GetBySessionKey(sessionKey);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid user!"));
            }

            newsArticle.Author = user.Nickname;

            NewsArticle newsArticleEntity = null;

            try
            {
                newsArticleEntity = NewsArticlesMapper
                                    .ToNewsArticleEntity(newsArticle, usersRepository, commentsRepository);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid news article model provided!"));
            }

            newsArticle.ID = newsArticleEntity.ID;

            AddImages(newsArticle, newsArticleEntity);

            this.newsArticlesRepository.Add(newsArticleEntity);

            return(Request.CreateResponse(HttpStatusCode.Created, newsArticle));
        }
        public HttpResponseMessage EditNewsArticle(string sessionKey, int id, NewsArticleModel newsArticle)
        {
            User user = null;

            try
            {
                user = this.usersRepository.GetBySessionKey(sessionKey);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid user!"));
            }

            if (id != newsArticle.ID)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            NewsArticle updatedNewsArticle = null;

            try
            {
                updatedNewsArticle =
                    NewsArticlesMapper.ToNewsArticleEntity(newsArticle, usersRepository, commentsRepository);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid news article model provided!"));
            }

            this.newsArticlesRepository.Update(id, updatedNewsArticle);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }