0

I will start out by saying I am a bit of a noob when it comes to C# and Sitecore, but I am getting better.

I am trying to update our code to use a droplink control for an event item (we'll call it StringEventID), instead of a text field where users entered a GUID string (too many mistakes were made). Instead, we want to use a droplink that shows a list of active events.

We created a new droplink field within the template, called Event ID. It has two data items, Event (name of the event) and EventID (GUID). We added the new field to the existing Event template and it appears in SC as expected, with the droplink showing the event name as key, and guid as the value.

Of course, because we are using a droplink, we have to convert the GUID that comes through, which is only a pointer to the actual value we want, the GUID for the event itself.

Because so much of our code has been written with the filed StringEventID that it is impractical to update all of the code to convert the new GUID into string. What we are hoping to do is in the ViewModel, update the code that originally just passed through the string, to now read the GUID, convert it to string, and then pass it along to the controller as a string.

What is the best way to do this? Based on online research, I have build the following in the concrete model, but I get an error, saying that it does not have the matching return type of string.

[SitecoreType(TemplateId = "{36371859-7FF2-47D0-86F1-1579416AA584}", AutoMap = true)]
public class NetForumEvent : Event, INetForumEvent
{
    public MyLinkedItem NetForumID { get; set; }
    ...
 }
[SitecoreType(TemplateId = "{36371859-7FF2-47D0-86F1-1579416AA584}", AutoMap = true)]
public class MyLinkedItem : NetForumEvent, IMyLinkedItem
{
    [SitecoreField("Event ID")]
    public string EventId
    {
        get { return Convert.ToString(EventID); }
        set
        {
            string id = Convert.ToString(EventID);
            id = value;
        }
    }
}

In the abstract model, I have:

public interface IMyLinkedItem : INetForumEvent
{
    string EventId { get; set; }
}

public interface INetForumEvent : IEvent
{
    string NetForumID { get; set; }

The exact error language is:

'NetForumEvent' does not implement interface member
'INetForumEvent.NetForumID'. 'NetForumEvent.NetForumID' cannot
implement 'INetForumEvent.NetForumID' because it does not have the
matching return type of 'string'.

Many thanks in advance!

1 Answer 1

1

You are getting the error because your concrete class NetForumEvent is not implementing the interface properly.

You have:

public MyLinkedItem NetForumID { get; set; }

in the concrete class and:

string NetForumID { get; set; }

In your interface. Change your interface property to return a IMyLinkedItem object and then your code will compile and return the correct object for the mapping.

You will also need to change the concrete class to return the IMyLinkedItem instead of the MyLinkedItem

3
  • Thanks for the pointer - I updated the interface like this: Commented Jul 6, 2018 at 20:28
  • Sorry - comments got cut off. I updated the interface like this: public interface INetForumEvent : IEvent { //string NetForumID { get; set; } IMyLinkedItem NetForumID { get; set; } But I am still getting an error in the concrete class. Commented Jul 6, 2018 at 20:35
  • Actually, looking back on this question, I got off track halfway through the process. I am just getting back to trying to finish this up, and in looking at, I realize what I should be doing is in my concrete class, I should be trying to parse the droplink field values and converting to string there. Commented Jul 30, 2018 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.