Query help

Topics: Customizing Orchard, Writing modules
Aug 1, 2011 at 4:01 PM
Edited Aug 1, 2011 at 4:02 PM

Hey all!

I'm busy learning Orchard, ASP.NET and C# all at the same time for a project I'm working on. On this site I need an FAQ module. Everything is in the galery except an FAQ. So I make my own :)

Now everything is just working fine. I made two content types, FAQ and FAQ List. All FAQ's have a category and the FAQ List will show you the FAQs under a specified category. With some help from the web I have a working example. But here comes the troubles.

I can get the Title from the FAQ's. But I have no idea how to get my own stuff (like Question and Answer) from the SQL query. Here is what I have now.

	IEnumerable<FaqPart> parts = 
		_cms.Query<FaqPart, FaqPartRecord>()
		.Where(tpr => tpr.Category.Contains(flist.Category))
		.Join<CommonPartRecord>()			
		.OrderByDescending(cpr => cpr.PublishedUtc)
		.List();

	var list = shapeHelper.List();
	list.AddRange(parts.Select(p => _cms.BuildDisplay(p, "Summary")));

I hope someone could direct me to the right way. I know it has something to do with the part.Select. But I can't find any documentation as how to proceed.

Thank you for your help!

Coordinator
Aug 1, 2011 at 7:25 PM

Can you give some more details about how you implemented the questions and answers?

Aug 2, 2011 at 8:26 AM
Edited Aug 2, 2011 at 9:06 AM

Bertrand,

Here is the full package. All working except for my problem above :)

http://dl.dropbox.com/u/1739265/Orchard.Module.bdb.faq.1.0.nupkg

Thanks for looking into this!

Edit: It has an dependency with CKEditor
http://orchardproject.net/gallery/List/Modules/Orchard.Module.CKEditor

Coordinator
Aug 2, 2011 at 11:28 PM

I'm sorry, I simply do not have time to go into the code and debug it for you. I was more asking for a description of what you did.

Aug 3, 2011 at 8:16 AM

Abosolutely no problem Bertrand!

There are two new content types. FAQ and FAQ List. Both have a field called "Category". I both made them very basic just like the in the tutorial "Creating a module using a text editor"

I think I can make this thing work cause I now get all the info through another way.

		IEnumerable<FaqPart> parts = 
			_cms.Query<FaqPart, FaqPartRecord>()
			.Where(fpr => fpr.Category.Contains(flist.Category))
			.Join<CommonPartRecord>()			
			.OrderByDescending(cpr => cpr.PublishedUtc)
			.List();

		// Create a list and push our display content items in
		var zlist = shapeHelper.List();
		zlist.AddRange(parts.Select(p => _cms.BuildDisplay(p, "Summary")));		
		
		var xlist = shapeHelper.List();		
		foreach(var item in parts)
		{
			FaqPartRecord fp = new FaqPartRecord();
			fp.Question = item.Question;
			fp.Answer = item.Answer;
			fp.Category = item.Category;
			fp.SubCategory = item.SubCategory;
			//fp.ContentItem = item.ContentItem;
			fp.Id = item.Id;
			xlist.Add(fp);
		}
		
		return ContentShape("Faq_List",
			() => shapeHelper.Parts_FaqList(
			ContentItems : zlist,
			Category : flist.Category,
			Faqs: xlist
		));	

This is how I implemented FaqPartRecord and FaqPart

  public class FaqPartRecord : ContentPartRecord {
	[StringLengthMax]
    public virtual string Question { get; set; }
	[StringLengthMax]
    public virtual string Answer { get; set; }
	public virtual string Category { get; set; }
	public virtual string SubCategory { get; set; }
  }

  public class FaqPart : ContentPart<FaqPartRecord> {

The only thing I can't get to work is "//fp.ContentItem = item.ContentItem;"

Will probably do something wrong. Will go and check further :)

Thanks for looking at this silly topic :)

Aug 3, 2011 at 10:10 AM

And here is my solution. It's just way more simpler then I tought :D

		IEnumerable<FaqPart> parts = 
			_cms.Query<FaqPart, FaqPartRecord>()
			.Where(fpr => fpr.Category.Contains(flist.Category))
			.Join<CommonPartRecord>()			
			.OrderByDescending(cpr => cpr.PublishedUtc)
			.List();

		return ContentShape("Faq_List",
			() => shapeHelper.Parts_FaqList(
			Category : flist.Category,
			Faqs: parts
		));	

I just needed to send the results of the query to the view and sort it all out in the view! When I'm done with module I will post it in the Galery!

Thanks for looking into this!

Coordinator
Aug 3, 2011 at 11:48 PM

There you go! Congratulations on figuring it out :)