Fetching Content Part

Topics: Administration, General
Dec 16, 2013 at 5:51 AM
Edited Dec 16, 2013 at 9:31 AM
I need to search/query of content type that has content part "course" attached to it, this should bring list of courses.

Model

using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Records;
using Orchard.ContentManagement.Utilities;

namespace Course.Models
{
    public class CoursePart : ContentPart<CoursePartRecord>
    {
        public string Name
        {
            get { return Record.Name; }
            set { Record.Name = value; }
        }

        public string Description
        {
            get { return Record.Description; }
            set { Record.Description = value; }
        }
    }

    public class CoursePartRecord : ContentPartRecord
    {
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
    }
}

Menu

using Orchard.Localization;
using Orchard.UI.Navigation;

namespace Course
{
    public class AdminMenu : INavigationProvider
    {
        public string MenuName
        {
            get { return "admin"; }
        }

        public AdminMenu()
        {
            T = NullLocalizer.Instance;
        }

        private Localizer T { get; set; }

        public void GetNavigation(NavigationBuilder builder)
        {
            builder
                // "Webshop"
                .Add(item => item
                    // "Course"
                    .Add(subItem => subItem
                        .Caption(T("Course"))
                        .Position("2.1")
                        .Action("Index", "CourseAdmin", new { area = "Course" })
                    )
                );
        }
    }
}

View Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Course.ViewModels
{
    public class CourseIndexVM
    {
        public IList<dynamic> Courses { get; set; }
        public dynamic Pager { get; set; }
        public CourseSearchVM Search { get; set; }

        public CourseIndexVM()
        {
            Search = new CourseSearchVM();
        }

        public CourseIndexVM(IEnumerable<dynamic> courses, CourseSearchVM search, dynamic pager)
        {
            Courses = courses.ToArray();
            Search = search;
            Pager = pager;
        }
    }
}

Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Course.ViewModels;
using Orchard.DisplayManagement;
using Orchard.Settings;
using Orchard.UI.Admin;
using Orchard.UI.Navigation;

namespace CourseAdmin.Controllers
{
        [Admin]
        public class CourseAdminController : Controller
        {
            private dynamic Shape { get; set; }
            private readonly ISiteService _siteService;

            public CourseAdminController(IShapeFactory shapeFactory, ISiteService siteService)
            {
                Shape = shapeFactory;                
                _siteService = siteService;
            }

            public ActionResult Index(PagerParameters pagerParameters, CourseSearchVM search)
            {                
                //code to fetch course here and return to model
            }
        }    
}
Coordinator
Dec 16, 2013 at 11:42 PM
You did not show what CourseSearchVM is or what the view that posts to that action looks like.