Copied to clipboard

Flag this post as spam?

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


  • Losh 5 posts 35 karma points
    May 19, 2014 @ 23:41
    Losh
    0

    Change a property value on all members

    Hi!

    I need to change the property value of a boolean i got on the members, and set them to true / false based on data in a CSV file. Kinda like so:

    if(PhoneNumberFromCsvFile == member.property("phoneNumber"){
         //Do nothing as property is false by default
    }else{
         //Set property to TRUE
    }
    

    (I'm aware the syntax is not correct, and that you should not have a empty if block like so, but hey, it's just so get the gist of what im trying to accomplish here.)

    I tried using Member.GetAllAsList(), and do a foreach; but it ended up taking like 5 seconds each time it iterated. (..and with nearly 100k members, pretty much no-go).

    Someone know of a quicker way to do this?

    All help is appreciated! :-)

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 20, 2014 @ 08:30
    Dave Woestenborghs
    0

    Can you post your entire code. 

    Dave

  • Losh 5 posts 35 karma points
    May 20, 2014 @ 17:37
    Losh
    0

    Well, this was just something i sketched, so it's not.. exactly optimized!

    public void SetReceiveSmsFromCsv()
            {
                var numbers = System.IO.File.ReadAllLines(@"C:\Users\Documents\GitHub\receiveSMSList.csv");
                var members = Member.GetAllAsList();
                bool found = false;
                foreach(var member in members)
                {
                    found = false;
                    foreach (var number in numbers)
                    {
                        if (member.getProperty("phone").Value.ToString().Contains(number))
                        {
                            found = true;
                            break;
                        }
    
                    }
                    if (!found)
                    {
                        member.getProperty("recieveSms").Value = true;
                        member.Save();
                    }
    
                }
            }
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 21, 2014 @ 09:03
    Dave Woestenborghs
    0

    Hi,

    Code seems okay. What line of code is slow. Is it the updating of the property or getting all the members ?

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft