コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public ActionResult Index()
        {
            var topics = _repo.GetTopics().OrderBy(t => t.Created)
                         .Take(25)
                         .ToList();

            return(View(topics));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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());
        }
コード例 #8
0
ファイル: TopicsController.cs プロジェクト: dikili/commerce
        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);
        }
コード例 #9
0
        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());
                }
            }
        }