Retreiving a Part's field

Topics: Customizing Orchard, General
Nov 10, 2012 at 3:10 PM

I'm sitting in a controller and have retrieved the given user via:

var user=
_orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.Email == email);

 

The UserPart model has a field named: idInstitution. How do I access this value?

thx

Nov 11, 2012 at 12:13 AM

 

 var fields = ((ContentItem)part.ContentItem).Parts.SelectMany(p => p.Fields);                       

string Status = fields.Where(f => f.Name == "Status").First().Storage.Get<string>(null);

Coordinator
Nov 11, 2012 at 5:05 AM

There's easier:

dynamic contentItem = part.ContentItem;
var id = contentItem.UserPart.IdInstitution.Value;

Nov 11, 2012 at 12:15 PM

Thanks - both snippets are failing to resolve 'part'.

Coordinator
Nov 11, 2012 at 7:07 PM

Oh come on ;) Substitute with whatever variable name you have. Seems like in your case it's "user".