Creating driver for n-n realtions

Topics: General
May 27, 2014 at 8:01 PM
The main goal is to create a recommendation system for advertisements (posts).
On orchard I found how to create part for N-N relation (N-N because for every post there is a recommendation for every user).
So the problem is, I don't know how to display related posts to current one.
This is how I try:
public class SuggestionRatePart : ContentPart<SuggestionRatePartRecord>
    {
        public IEnumerable<UserSuggestionRatePart> SuggestionRates
        {
            get
            {
                return Record.SuggestionRates.Select(x => x.UserSuggestionRatePart);
            }
        }
    }

public class ContentSuggestionRateRecord
    {
        public virtual int Id { get; set; }
        public virtual SuggestionRatePartRecord SuggestionRatePartRecord { get; set; }
        public virtual UserSuggestionRatePart UserSuggestionRatePart { get; set; }
    }

public class SuggestionRatePartRecord : ContentPartRecord
    {
        public SuggestionRatePartRecord()
        {
            SuggestionRates = new List<ContentSuggestionRateRecord>();
        }

        public virtual IList<ContentSuggestionRateRecord> SuggestionRates { get; set; }
    }

public class UserSuggestionRatePart
    {
        public virtual int Id { get; set; }

        public virtual double Recommendation { get; set; }

        public virtual int UserId { get; set; }
    }
}

public class SuggestionRateDriver : ContentPartDriver<SuggestionRatePart>
    {
        private ISuggestionRateService suggestionService;

        public SuggestionRateDriver(ISuggestionRateService suggestionService)
        {
            this.suggestionService = suggestionService;
        }

        protected override DriverResult Display(SuggestionRatePart part, string displayType, dynamic shapeHelper)
        {
            /*return ContentShape("Parts_Suggestions",
                () => shapeHelper.Parts_Suggestions(
                ViewModel: BuildEditorViewModel(part),
                Prefix: Prefix));*/
            //Here I don't realy know what to do
        }

        private object BuildEditorViewModel(SuggestionRatePart part)
        {
            return new SuggestionRateViewModel()
            {
                //Here i think to receive related posts from service
            };
        }
    }
Will be very thankful if someone points me what to do or for some guidelines