コード例 #1
0
        public String GetJSONPosts()
        {
            String sql = "SELECT TOP 3 * FROM appadmin.Blogs ORDER BY CreatedOn DESC";

            List <Blog> blogs = SqlFuDAL.FindObjectsByType <Blog>(sql);

            List <Tag>     tags    = new List <Tag>();
            PostCollection postCol = new PostCollection();

            sql = @"SELECT t.TagName, t.TagURL
FROM appadmin.Tags t
INNER JOIN appadmin.BlogTags bt ON t.ID = bt.TagID
WHERE bt.BlogID = {0}";

            foreach (Blog blog in blogs)
            {
                String query = String.Format(sql, blog.ID);
                //Build Post:
                tags      = SqlFuDAL.FindObjectsByType <Tag>(query);
                blog.Tags = tags;
                //massage CreatedOn property to contain just date part
                blog.CreatedOnDate = blog.CreatedOn.ToShortDateString();
                postCol.Posts.Add(blog);
            }

            String     json     = JsonConvert.SerializeObject(postCol);
            JsonResult jsonData = new JsonResult {
                Data = JsonConvert.DeserializeObject(json)
            };

            return(jsonData.Data.ToString());
        }
コード例 #2
0
        public String GetJSONConferences()
        {
            List <Conference>    conferences   = SqlFuDAL.FindObjectsByType <Conference>();
            ConferenceCollection conferenceCol = new ConferenceCollection();

            conferenceCol.Conferences = conferences;

            String     json     = JsonConvert.SerializeObject(conferenceCol);
            JsonResult jsonData = new JsonResult {
                Data = JsonConvert.DeserializeObject(json)
            };

            return(jsonData.Data.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Returns all articles found in database.
        /// </summary>
        /// <returns></returns>
        public String GetJSONArticles()
        {
            List <Article>    articles   = SqlFuDAL.FindObjectsByType <Article>();
            ArticleCollection articleCol = new ArticleCollection();

            articleCol.Articles = articles;

            String     json     = JsonConvert.SerializeObject(articleCol);
            JsonResult jsonData = new JsonResult {
                Data = JsonConvert.DeserializeObject(json)
            };

            return(jsonData.Data.ToString());
        }
コード例 #4
0
        public String GetJSONParticipants()
        {
            //build json object to populate Participants view:
            //query Participants table to retrieve needed info
            List <Participant> participants = SqlFuDAL.FindObjectsByType <Participant>();

            //perform any needed translation into JSON friendly object here:
            ParticipantCollection participantCol = new ParticipantCollection();

            participantCol.Participants = participants.Where(p => p.IsActive).ToList();
            String json = JsonConvert.SerializeObject(participantCol);

            JsonResult jsonData = new JsonResult {
                Data = JsonConvert.DeserializeObject(json)
            };

            //return JSON object back to the view
            return(jsonData.Data.ToString());
        }
コード例 #5
0
        public ActionResult Articles()
        {
            List <Article> articles = SqlFuDAL.FindObjectsByType <Article>();

            return(View(articles));
        }