Example #1
0
        public ArticlePublishResponse LikeArticle(User user, Article article)
        {
            DataWriteResult result = _articleRepository.Like(user, article);

            ArticlePublishResponse response = result.Success ? ResponseBase.SuccessResponse() : ResponseBase.FailureResponse();

            return(response);
        }
Example #2
0
        public ArticlePublishResponse Publish(User publisher, Article article)
        {
            DataWriteResult result = _articleRepository.Create(publisher, article);

            ArticlePublishResponse response = result.Success ? ResponseBase.SuccessResponse() : ResponseBase.FailureResponse();

            return(response);
        }
Example #3
0
        public ActionResult Like(int id)
        {
            var user    = (User)Session["LoggedInUser"];
            var article = new Article()
            {
                Id = id
            };
            ArticlePublishResponse response = _articleManager.LikeArticle(user, article);

            return(Json(response.Success));
        }
        public HttpResponseMessage Publish(int userId, Models.Publish.ArticleViewModel articleViewModel)
        {
            var user = new User {
                Id = userId
            };
            var article = Mapper.Map <Article>(articleViewModel);
            ArticlePublishResponse publishResponse = _articleManager.Publish(user, article);
            var response = publishResponse.Success
                ? Request.CreateResponse(HttpStatusCode.OK)
                : Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Failure");

            return(response);
        }
Example #5
0
        public void PublishArticle_NoUser_Failure()
        {
            var article = new Article
            {
                Title       = "Sports Article",
                Body        = "This is a new sport article",
                ArticleType = ArticleType.Sports,
                PublishDate = DateTime.Now
            };
            ArticlePublishResponse response = _articleManager.Publish(_publisher, article);

            Assert.AreEqual(false, response.Success);
        }
Example #6
0
        public void PublishArticle_Successful()
        {
            var article = new Article
            {
                Title       = "Sports Article",
                Author      = _author,
                Body        = "This is a new sport article",
                ArticleType = ArticleType.Sports,
                PublishDate = DateTime.Now
            };
            ArticlePublishResponse response = _articleManager.Publish(_publisher, article);

            Assert.AreEqual(true, response.Success);
        }
        public HttpResponseMessage Like(int userId, int articleId)
        {
            var user = new User {
                Id = userId
            };
            var article = new Article {
                Id = articleId
            };
            ArticlePublishResponse publishResponse = _articleManager.LikeArticle(user, article);
            var response = publishResponse.Success
                ? Request.CreateResponse(HttpStatusCode.OK)
                : Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Failure");

            return(response);
        }
Example #8
0
        public void LikeArticle_InsufficientLikes_Successful()
        {
            _employee.Likes = 0;
            var article = new Article
            {
                Title       = "Sports Article",
                Author      = _author,
                Body        = "This is a new sport article",
                ArticleType = ArticleType.Sports,
                PublishDate = DateTime.Now,
                Likes       = 5
            };
            ArticlePublishResponse response = _articleManager.LikeArticle(_employee, article);

            Assert.AreEqual(false, response.Success);
            Assert.AreEqual(5, article.Likes);
        }