Exemplo n.º 1
0
 public HttpResponseMessage Get()
 {
     try
     {
         IList<TopicViewModel> topicViewModels = new List<TopicViewModel>();
         TopicViewModel topicViewModel;
         IQueryable<Topic> topics;
         topics = _topicService.GetTopics();
         foreach (Topic topic in topics)
         {
             topicViewModel = new TopicViewModel(topic);
             topicViewModels.Add(topicViewModel);
         }
         return Request.CreateResponse(HttpStatusCode.OK, topicViewModels);
     }
     catch
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }
Exemplo n.º 2
0
 public HttpResponseMessage Get(string searchString,int page=1)
 {
     try
     {
         ApiListContainerModel<TopicViewModel> apiListContainerModel = new ApiListContainerModel<TopicViewModel>();
         TopicViewModel topicViewModel;
         IQueryable<Topic> topics = _topicService.SearchForTopics(searchString).OrderBy(o=>o.TopicName);
         var result=topics.Skip((page - 1) * _pageSize).Take(_pageSize).ToList();
         foreach (Topic topic in result)
         {
             topicViewModel = new TopicViewModel(topic);
             apiListContainerModel.List.Add(topicViewModel);
         }
         apiListContainerModel.Page = page;
         apiListContainerModel.PageCount = topics.Count() / _pageSize+1;
         return Request.CreateResponse(HttpStatusCode.OK, apiListContainerModel);
     }
     catch
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }