コード例 #1
0
ファイル: ListModel.cs プロジェクト: stantoxt/Piranha.vNext
        /// <summary>
        /// Gets the post list model.
        /// </summary>
        /// <param name="slug">Optional post type slug</param>
        /// <returns>The model</returns>
        public static ListModel Get(string slug = null)
        {
            using (var api = new Api()) {
                var m = new ListModel();

                if (!String.IsNullOrWhiteSpace(slug))
                {
                    m.Items = api.Posts.Get(where : p => p.Type.Slug == slug).Select(p => new PostListItem()
                    {
                        Id        = p.Id,
                        Title     = p.Title,
                        Type      = p.Type.Name,
                        Created   = p.Created,
                        Updated   = p.Updated,
                        Published = p.Published
                    }).ToList();
                    m.IsDefaultSelection = false;
                }
                else
                {
                    m.Items = api.Posts.Get().Select(p => new PostListItem()
                    {
                        Id        = p.Id,
                        Title     = p.Title,
                        Type      = p.Type.Name,
                        Created   = p.Created,
                        Updated   = p.Updated,
                        Published = p.Published
                    }).ToList();
                }
                m.PostTypes = api.PostTypes.Get().Select(t => new PostTypeListItem()
                {
                    Name     = t.Name,
                    Slug     = t.Slug,
                    IsActive = t.Slug == slug
                }).ToList();
                return(m);
            }
        }
コード例 #2
0
ファイル: ListModel.cs プロジェクト: cdie/Piranha.vNext
		/// <summary>
		/// Gets the post list model.
		/// </summary>
		/// <param name="slug">Optional post type slug</param>
		/// <returns>The model</returns>
		public static ListModel Get(string slug = null) {
			using (var api = new Api()) {
				var m = new ListModel();

				if (!String.IsNullOrWhiteSpace(slug)) {
					m.Items = api.Posts.Get(where: p => p.Type.Slug == slug).Select(p => new PostListItem() {
						Id = p.Id,
						Title = p.Title,
						Type = p.Type.Name,
						Created = p.Created,
						Updated = p.Updated,
						Published = p.Published
					}).ToList();
					m.IsDefaultSelection = false;
				} else {
					m.Items = api.Posts.Get().Select(p => new PostListItem() {
						Id = p.Id,
						Title = p.Title,
						Type = p.Type.Name,
						Created = p.Created,
						Updated = p.Updated,
						Published = p.Published
					}).ToList();
				}
				m.PostTypes = api.PostTypes.Get().Select(t => new PostTypeListItem() {
					Name = t.Name,
					Slug = t.Slug,
					IsActive = t.Slug == slug
				}).ToList();
				return m;
			}
		}