public HttpResponseMessage GetAllTopics()
        {
            List <Topic> topics = null;

            try
            {
                if (ModelState.IsValid)
                {
                    topics = _bltopic.GetAllTopics();

                    if (topics.Count == 0)
                    {
                        log.Error("Reuested data has null entries");
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, topics));
                    }
                }
                else
                {
                    log.Error("Invalid model state encountered.");

                    return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Example #2
0
        public void TopicGetAll()
        {
            validation.GetAllTopics().Returns(topicList);
            topicController.Request       = new HttpRequestMessage();
            topicController.Configuration = new HttpConfiguration();
            var actionResult = topicController.GetAllTopics();

            Assert.AreEqual(HttpStatusCode.OK, actionResult.StatusCode);
        }
        public CategoryPage CreateCategoryPage()
        {
            var topic = _topicService.GetAllTopics().Select(topic => new TopicListing
            {
                CategoryId    = topic.Category.Id,
                TopicId       = topic.Id,
                CategoryTitle = topic.Category.Title,
                AuthorName    = topic.User.UserName,
                TopicTitle    = topic.Title,
                PostCount     = topic.Posts.Count(),
                DateCreated   = topic.Created.ToString()
            });

            return(new CategoryPage()
            {
                Topics = topic
            });
        }
 public IEnumerable <Topic> GetAll()
 {
     return(_topicService.GetAllTopics());
 }