Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Darren Wilson 229 posts 597 karma points
    Sep 26, 2017 @ 09:18
    Darren Wilson
    0

    Displaying multinode picker within list of members

    Hi Folks,

    I've got a multinode picker as a custom data type within a member - I can't pull back the data to the front end as a list.

    @foreach (var member in ApplicationContext.Current.Services.MemberService.GetAllMembers().OrderBy(member => member.Name))
    
    {
                <tr> 
    
                    <td>@member.Name </td> 
                    <td>@member.Email</td> 
                    <td>@member.GetValue("TownCity")</td>
                    <td>@member.GetPropertyValue<IPublishedContent>("Pharmacy")</td>
    
                </tr> 
    
            }
    

    I would think the last row should work but it's throwing an error - Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

    Not tried this before, so I'm a bit stuck. Any ideas will be greatly appreciated.

    Cheers Darren

  • Craig Mayers 164 posts 508 karma points
    Sep 26, 2017 @ 11:29
    Craig Mayers
    0

    Hi Darren,

    When you say the last line, do you mean:

    <td>@member.GetPropertyValue<IPublishedContent>("Pharmacy")</td>
    

    If so, is there a Property on the MemberDocType named "Pharmacy" and is it a node?

    Thanks

    Craig

  • Darren Wilson 229 posts 597 karma points
    Sep 26, 2017 @ 12:02
    Darren Wilson
    0

    Hi Craig,

    Thanks for getting back to me - that's the correct line. There's a multi node picker on the MemberDocType called Pharmacy.

    Cheers Darren

  • Craig Mayers 164 posts 508 karma points
    Sep 26, 2017 @ 12:16
    Craig Mayers
    0

    Hi Darren,

    You should be able to do something like below:

    var selectedPharmacy = member.GetPropertyValue<IEnumerable<IPublishedContent>>("pharmacy");
    

    This should return a list of selected IPublishedContent objects.

    Thanks

    Craig

  • Julian 7 posts 76 karma points
    Feb 21, 2019 @ 11:38
    Julian
    0

    Dead topic, but this is the closest i could find to my problem.

         var listOfTradesmen = listOfMembers.Where(tradesman => tradesman.ContentType.Alias.Equals("tradesmanMember") && tradesman.GetValue<IEnumerable<IPublishedContent>>("services").Select(service => service.Id).Intersect(categoryServicesAsListOfIds).Any());
    

    I have an MNTP as a field for Members, and by looking at the ModelsBuilder generated code of my member type, I did exactly the same code you suggested Darren, but alas I get a 'Value cannot be null' exception.

    The field names match, and if I remove the IEnumerable return type so that I let the method decide what to return back, it returns back a stringified list of UDIs, which only complicates fitlering and searching of members now.

    By any chance, do you know if I can simplify or make minimal changes to my code so that I do not need to mess around with UDIs, convert to GUID, look them up, etc etc. ? The process seems unnecessarily complicated now.

  • Silvija 58 posts 172 karma points
    Apr 05, 2019 @ 11:31
    Silvija
    0

    Hi Julian, did you found solution for this?

  • Julian 7 posts 76 karma points
    Apr 12, 2019 @ 12:14
    Julian
    0

    Hi Silvija,

    My solution was to go along with the UDIs.

    I had made a helper class containing 2 methods, one to look up the UDI as a typed content and the other to read a list of them.

    public static IPublishedContent GetPublishedContentByUdi(string udi)
        {
            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
            return udi.IfNotNull(x => umbracoHelper.TypedContent(x)) ?? default(IPublishedContent);
        }
    
    /// <summary>
        /// Takes a stringified list of UDIs to return as IEnumerable of type IPublishedContent
        /// </summary>
        /// <param name="udi"></param>
        /// <returns></returns>
        public static IEnumerable<IPublishedContent> GetPublishedContentByListOfUdis(object udi)
        {
            return udi
                .IfNotNull(x => x
                    .ToString()
                        .Split(',')
                            .Select(GetPublishedContentByUdi)) ?? Enumerable.Empty<IPublishedContent>();
        }
    

    In the end, my code for my scenario from my previous post came to look like so (the name of my helper is PublishedContentHelper):

    var allTradesmen = ApplicationContext.Current.Services.MemberService
                .GetAllMembers()
                .Where(tradesman => tradesman.ContentType.Alias.Equals(ConstantValues.TradesmanMemberTypeAlias))
                .Where(tradesman =>
                    filterModel.ListOfSubscriptionOptions
                        .Select(x => x.Id)
                        .Intersect(
                            PublishedContentHelper.GetPublishedContentByListOfUdis(
                                    tradesman.GetValue(ConstantValues.Tradesman_Member_Field_Subscription)
                                    )
                                        .Select(subId => subId.Id))
                                        .Any()
                )
                .ToList();
    
Please Sign in or register to post replies

Write your reply to:

Draft