public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; var topics = _repo.GetTopics() .OrderByDescending(t => t.Created) .Take(25) .ToList(); return(View(topics)); }
public IHttpActionResult Get(bool includeReplies = true, int page = 0, int pageSize = 2) { IEnumerable <Topic> topics; if (includeReplies) { try { topics = _repo.GetTopicsIncludeReplies().OrderBy(t => t.Id); var totalCount = topics.Count(); var totalPages = (int)Math.Ceiling((double)totalCount / pageSize); var pager = topics .Skip(pageSize * page) .Take(pageSize) .ToList(); var result = new { totalcount = totalCount, totalPages = totalPages, PageSize = pageSize, topics = pager }; return(Ok(result)); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(BadRequest()); } } else { topics = _repo.GetTopics().Take(10).ToList(); } return(Ok(topics)); }
public ActionResult Index() { var topics = _repo.GetTopics().OrderBy(t => t.Created) .Take(25) .ToList(); return(View(topics)); }
public IEnumerable <Topic> Get(bool includeReplies = false) { IQueryable <Topic> results; if (includeReplies == true) { results = _repo.GetTopicsIncludingReplies(); } else { results = _repo.GetTopics(); } var topics = results.OrderByDescending(t => t.Created) .Take(25) .ToList(); return(topics); }
public IEnumerable <Topic> Get(bool includeReplies = false) { IEnumerable <Topic> results; if (includeReplies) { results = _repo.GetTopicsIncludingReplies().OrderByDescending(t => t.Created).Take(25).ToList(); } else { results = _repo.GetTopics().OrderByDescending(t => t.Created).Take(25).ToList(); } return(results); }
public ActionResult Index() { var topics = _repo.GetTopics() .OrderByDescending(t => t.Created) .Take(25) .ToList(); foreach (var topic in topics) { topic.Replies = _repo.GetRepliesByTopic(topic.Id).ToList(); } return(View(topics)); }
public IEnumerable <Topic> Get(bool includeReplies = false) { IQueryable <Topic> results; if (includeReplies) { results = _messageBoardRepository.GetTopicsIncludingReplies(); } else { results = _messageBoardRepository.GetTopics(); } return(results.OrderByDescending(t => t.Created) .Take(25) .ToList()); }
public IEnumerable <Topic> Get(bool IncludeReplies = false) { IQueryable <Topic> result; if (IncludeReplies) { result = _repo.GetTopicsIncludingReplies(); } else { result = _repo.GetTopics(); } var topics = result.OrderByDescending(t => t.Created).Take(25); return(topics); }
public IHttpActionResult Post(int topicId, [FromBody] Reply reply) { var topic = _repo.GetTopics().FirstOrDefault(t => t.Id == topicId); if (topic == null) { return(BadRequest()); } else { reply.Created = DateTime.Now; reply.TopicId = topicId; if (_repo.AddReply(reply) && _repo.Save()) { return(CreatedAtRoute("replies", new { id = reply.Id }, reply)); } else { return(BadRequest()); } } }