Trouble implementing CyberStride.Contacts

Topics: General, Troubleshooting
Jan 24, 2012 at 2:23 PM

I'm trying to implement the Cyberstride.Contacts module, but I'm actually having trouble understanding how to change some code related to the IContentManager. So I'm posting here.

The issue is that I'm receiving a blank email message. I've narrowed down the issue (I think) to the following:

Within ContactMessagesAlteration.cs, on line 26:


        public void Sending(MessageContext context) {
            if (context.MessagePrepared)

        //this line gives NullReference exception.   
var contentItem = _contentManager.Get(context.Recipient.Id); if ( contentItem == null ) return; var recipient = contentItem.As<ContactFormPart>(); if ( recipient == null ) return;

Basically, "context.Recipient.Id" does not exist. In another part of the code (MessageContext.cs), it indicates that Recipient is obsolete, and that I should use Recipients instead. But I don't know how to get a contentItem from _contentManager using Recipients. I just boils down to my not understanding how to get a content item without having an id (not sure that's possible), or figuring out the id I need from Recipients (instead of Recipient).

Thanks for any guidance.



Jan 24, 2012 at 3:17 PM

In Controlllers\ContactController.cs line 37, Modify the code :
            var model = Services.ContentManager.Create<ContactPart>("Contact");


            var model = Services.ContentManager.New<ContactPart>("Contact");

Jan 24, 2012 at 3:36 PM

I see code similar to this in ContactService.cs, but not in ContactController.cs. 

Is this what you're referring to? Or do you in fact mean to use this code to create a local variable named model in the Controller?

Jan 24, 2012 at 4:09 PM

Recheck : it is in Controllers\ContactController.cs, line 37 in the source code I have. Or search a part of the text to find it.

Replace 'Create' by 'New' to avoid to create an empty contact.

Jan 24, 2012 at 9:00 PM

Found it. Thanks!

May 29, 2012 at 4:19 AM
Edited May 29, 2012 at 5:51 AM
timshortt wrote:

Found it. Thanks!

Orchard Version 1.4.2

//this line gives NullReference exception.   
var contentItem = _contentManager.Get(context.Recipient.Id);

After following this suggestion above I was still having a problem.

I had to replace

     var contentItem = _contentManager.Get(context.Recipient.Id);


            int RecipientID = ((Orchard.ContentManagement.Records.ContentItemRecord[])(context.Recipients))[0].Id;             
            var contentItem = _contentManager.Get(RecipientID);

Also to get the display to show a correct date in admin site I needed to change the ContactController.cs file.

             var model = Services.ContentManager.Create<ContactPart>("Contact");

was changed to

            var model = Services.ContentManager.New<ContactPart>("Contact");