public static void RefreshAndSavePersonalizedContent(Member member, Child child)
        {
            DateTime now = DateTime.Now;

            List<UnderstoodDotOrg.Domain.Search.Article> articles = Domain.Search.SearchHelper.GetArticles(member, child, now);

            PersonalizationHelper.SavePersonalizedContent(member, child, articles);
        }
Ejemplo n.º 2
0
        public static List<Question> FindQuestions(Member user)
        {

             String [] issues = new List<string>(user.Children.Select(x => x.Issues.Select(k => k.Key.ToString("B").ToUpper())).SelectMany(x=>x)).ToArray();
                String[] grades = new List<string>(user.Children.Select(x => x.Grades.Select(g => g.Key.ToString("B").ToUpper())).SelectMany(x => x)).ToArray() ;
                String[] topics = user.Interests.Select(x => x.Key.ToString("B").ToUpper()).ToArray();
                //String[] states = new string[] { user.zipCodeToState() };
                //String[] partners = new string[0];
                return FindQuestions(issues, topics, grades);
        }
Ejemplo n.º 3
0
        public static MemberCardModel MemberCardModelFactory(Member m)
        {
            MemberCardModel mcModel = new MemberCardModel(); 
             if(m!=null)
             {
                 mcModel = new MemberCardModel(m, User.GetUserBadges);
                 mcModel.UserLocation = m.zipCodeToState();
             }

                 return mcModel;
        }
Ejemplo n.º 4
0
        private void doLogin()
        {

            //blow out any existing member when someone tries to sign in
            try
            {
                //Reset session backed my groups from Whats Happening Now
                Session["_selectedGroups"] = null;
               
                //lets make sure to reset all user&member info before we start inflating it
                this.FlushCurrentMemberUser();

                var membershipManager = new MembershipManager();

                var currentMember = new Member();

                if (!string.IsNullOrEmpty(AccessToken))
                {
                    var client = new Facebook.FacebookClient(AccessToken);
                    dynamic me = client.Get("me", new { fields = "email" });

                    currentMember = membershipManager.GetMember(me.email);
                }
                else
                {
                    currentMember = membershipManager.AuthenticateUser(uxEmailAddress.Text, uxPassword.Text);
                }

                if (currentMember != null)
                {
                    this.CurrentMember = currentMember;
                    this.CurrentUser = membershipManager.GetUser(currentMember.MemberId, true);

                    this.ProfileRedirect(Constants.UserPermission.AgreedToTerms, null, true);

                    //Redirect used here for profile??
                    this.ReturnRedirect();

                    var item = Sitecore.Context.Database.GetItem(Constants.Pages.MyAccount);
                    // if you get this far, clear the redirect session URL 

                    Response.Redirect(Sitecore.Links.LinkManager.GetItemUrl(item));
                }
            }
            catch (Exception ex)
            {
                uxError.Text = ex.Message;
            }
        }
Ejemplo n.º 5
0
        private void initialize(Member m, Func<string, List<UserBadgeModel>> badgesPop = null)
        {
            if (m != null)
            {
                if (!String.IsNullOrEmpty(m.ScreenName))
                {

                    this.AvatarUrl = Constants.Settings.AnonymousAvatar; ///TODO: find Avatar URL
                    this.Children = m.Children.ConvertToChildCardModelList();
                    this.UserLabel = "Blogger"; //TODO: find role                                                                                   
                    this.UserLocation = m.ZipCode;// Constants.Settings.DefaultLocation; //TODO: find location translate from zipcode
                    this.UserName = m.ScreenName;
                    this.Contactable = m.allowConnections;
                    this.ProfileLink = m.GetMemberPublicProfile();
                    if (badgesPop != null)
                        Badges = badgesPop(m.ScreenName);
                }
            }       
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ProfileUser != null)
            {
                // TODO: since we manage telligent users, we should be storing data on our member to avoid
                // unneeded api lookups
                var mm = new MembershipManager();
                _member = mm.GetMemberByScreenName(ProfileUser.Username);

                if (_member == null)
                {
                    return;
                }

                ProfileUrl = MembershipHelper.GetPublicProfileUrl(ProfileUser.Username);
                ProfileActivityUrl = MembershipHelper.GetPublicProfileActivityUrl(ProfileUser.Username);
            
                BindEvents();
                PopulateContent();
            }
        }
        public Member GetMember(Guid MemberId)
        {
            var parent = new Member()
            {
                FirstName = "Testing",
                LastName = "User",
                ScreenName = "JustTesting",
                ZipCode = "12345",
                Role = Guid.Parse("{2BF9D7BE-2E40-432C-ADE7-A25C80B9B9EE}"),
                PersonalityType = Guid.Parse("{8B7EB70D-64B2-45B9-B06E-6AA5CB6FE983}"),
                hasOtherChildren = false,
                allowConnections = false,
                allowNewsletter = false,
                isPrivate = false,
                Interests = new List<Interest>() {
                    new Interest() {
                        Key = Guid.Parse("{26A98810-4539-4BB7-8D6F-43CFE075AED3}"),
                        Value = "Apps",
                        CategoryName = "Technology and Apps",
                    }
                },
                Journeys = new List<Journey>() {
                    new Journey() {
                        Key = Guid.Parse("{CB9F1AC5-4E58-499C-8D07-8BC4E8D42F0F}"),
                        Value = "We've been working through my child's issues this past year.",
                    }
                },
                Children = new List<Child>() { 
                    new Child() {
                        Nickname = "Bobby",
                        IEPStatus = Guid.Parse("{73842143-B6CA-4B6A-A94F-BA59C475A6D7}"),
                        Section504Status = Guid.Parse("{82102C70-B526-47FB-BD99-5F71A33C3C87}"),
                        EvaluationStatus = Guid.Parse("{F6849A63-C841-4D79-BF53-AA68DA6D6EEB}"),
                        HomeLife = Guid.Parse("{8FFA90D9-F2DA-402D-9AC4-7C203769C810}"),
                        Gender = "boy",
                        Issues = new List<Issue>() { 
                            new Issue() {
                                Key = Guid.Parse("{FFB5F34E-5A5F-43C6-A987-9AFF713C66C9}"),
                                Value = "Attention or Staying Focused",
                            }  
                        },
                        Diagnoses = new List<Diagnosis>() { 
                            new Diagnosis() {
                                Key = Guid.Parse("{7A035CC2-D6BD-4332-9518-7AB22083F652}"),
                                Value = "ADHD",
                            }
                        },           
                        Grades = new List<Grade>() {
                            new Grade() {
                                Key = Constants.GradesByValue["3"],
                                Value = "3",
                            }
                        },
                    },
                    new Child() {
                        Nickname = "Sally",
                        IEPStatus = Guid.Parse("{73842143-B6CA-4B6A-A94F-BA59C475A6D7}"),
                        Section504Status = Guid.Parse("{82102C70-B526-47FB-BD99-5F71A33C3C87}"),
                        EvaluationStatus = Guid.Parse("{F6849A63-C841-4D79-BF53-AA68DA6D6EEB}"),
                        HomeLife = Guid.Parse("{8FFA90D9-F2DA-402D-9AC4-7C203769C810}"),
                        Gender = "girl",
                        Issues = new List<Issue>() { 
                            new Issue() {
                                Key = Guid.Parse("{FFB5F34E-5A5F-43C6-A987-9AFF713C66C9}"),
                                Value = "Attention or Staying Focused",
                            }  
                        },
                        Diagnoses = new List<Diagnosis>() { 
                            new Diagnosis() {
                                Key = Guid.Parse("{7A035CC2-D6BD-4332-9518-7AB22083F652}"),
                                Value = "ADHD",
                            }
                        },           
                        Grades = new List<Grade>() {
                            new Grade() {
                                Key = Constants.GradesByValue["5"],
                                Value = "5",
                            }
                        },
                    },
                },
            };

            return parent;
        }
 public Member AddMember(Member Member)
 {
     return this.GetMember(Guid.Empty);
 }
 public void UpdateMember(Member member)
 {
     foreach (var child in member.Children)
     {
         UpdateChild(member, child);
     }     
 }
        public SalesforceActionResult UpdateWebsiteMember(Member websiteMember)
        {
            SalesforceActionResult sfResult = new SalesforceActionResult();

            Contact salesforceContact = new Contact();
            //fill the contact with the current user's info
            //_sfs.retrieve(
            return sfResult;
        }
        /// <summary>
        /// Updates information about an existing member
        /// </summary>
        /// <param name="Member">Member to update</param>
        /// <returns>Member that was updated</returns>
        public Member UpdateMember(Member Member)
        {
            //if screen != null && telligentuser.getusrbyscreenname != null -> create user
            //TelligentService.GetPosesMember(string screenName)
            //CommunityHelper.CreateUser(screenname, email)

            //bg: Update member properties that are outside of entity:
            //    UpdateMember_ExtendedProperties checks a n data flag on member, 
            //    and does nothing if none of the new properties have been set outside of the database
            if (!this.UpdateMember_ExtendedProperties(Member))
            {
                throw new Exception("An error occured when trying to update extended member proprerties.");
            }


            try
            {
                if (!ClearnAllMemberInterests(Member.MemberId))
                {
                    throw new Exception("An error occured when trying to update member interests.");
                }
            }
            catch (Exception ex)
            {
                //log the exception 
                //bubble it up so the error can be displayed
                throw ex;
            }
            try
            {
                Member = this.mapMember(Member);

                _db.SaveChanges();

                return Member;
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var eve in ex.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw ex;
            }

        }
        /// <summary>
        /// Adds a new user to the authentication database, and then adds a new member to the membership database. 
        /// When in doubt, you probably want to use this one
        /// </summary>
        /// <param name="Member">Member to add</param>
        /// <param name="Username">Username (email addess) for ASP.Net Authentication</param>
        /// <param name="Password">Password for the user</param>
        /// <returns>Member that was added</returns>
        public Member AddMember(Member Member, string Username, string Password)
        {
            try
            {
                // use custom provider for authentication
                var provider = MembershipProvider.Providers[UnderstoodDotOrg.Common.Constants.MembershipProviderName];

                int existingUserCount;
                var isExistingUser = provider.FindUsersByEmail(Username, 0, 1, out existingUserCount);

                if (existingUserCount == 0)
                {
                    if (Member.MemberId == null || Member.MemberId == Guid.Empty)
                    {
                        Member.MemberId = Guid.NewGuid();
                    }

                    var status = new MembershipCreateStatus();

                    var user = provider.CreateUser(Username, Password, Username, null, null, true, Member.MemberId, out status);

                    if (status != MembershipCreateStatus.Success)
                    {
                        throw new Exception("Unable to create user. Reason: " + status);
                    }

                    Member = this.AddMember(Member);


                    return Member;
                }
                else
                {
                    throw new Exception("Username is not unique");
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Adds a new "shadow user" to the database
        /// </summary>
        /// <param name="Member"></param>
        /// <returns></returns>
        public Member AddUnauthorizedMember(Member Member)
        {
            //throw this out if there is no email 
            if (string.IsNullOrEmpty(Member.Email))
            {
                throw new Exception("Error in MembershipManager.cs. An email address must be provided to add a member.");
            }
            //bg: Note. We are going to use the ASP.Net Membership database's comment field
            //          to include a flag that can be used to identify users who only exist  in order 
            //          for us to generate content sent for Nebased on "The Algorithim" 
            //-- Setting up some values so that we know that this is not a standard website member
            //this member is probably only ever going to be created just so that we can generate personalized emails
            Member.Password = UnderstoodDotOrg.Common.Constants.UnauthenticatedMember_Password;
            Member.Comment = UnderstoodDotOrg.Common.Constants.UnauthenticatedMember_Flag;
            Member.ScreenName = UnderstoodDotOrg.Common.Constants.UnauthenticatedMember_ScreeName;

            Member m = new Member();
            try
            {
                m = this.AddMember(Member, Member.Email, Member.Password); //Need to refactor some code to account for Member having an email and password
            }

            catch (Exception e)
            {
                Exception e2 = new Exception("An Error occured when trying to create a new Unauthorized Member. Check InnerException", e);
                e2.Source = "MembershiopManager.cs In AddUnauthorizedMember(Member Member)";
                throw e2;
            }
            //now update the member to add the flag to let us know it is a unauthorized user
            AddMemberComment(m, UnderstoodDotOrg.Common.Constants.UnauthenticatedMember_Flag);

            return m;
        }
        /// <summary>
        /// This will be depreciated after we update the edmx but until then we are going to have a way to update all of the values that have been added on in Membership 1.2
        /// </summary>
        /// <param name="member">The Website Member that we want to update the databse with.</param>
        /// <returns></returns>
        public bool UpdateMember_ExtendedProperties(Member member)
        {
            bool success = false;
            try
            {

                string sql = "UPDATE  dbo.Members " +
                        " SET PreferedLanguage = @PreferedLanguage, " +
                        " AgreedToSignUpTerms = @AgreedToSignUpTerms, " +
                        " MobilePhoneNumber = @MobilePhoneNumber,  " +
                        " Subscribed_DailyDigest = @Subscribed_DailyDigest,  " +
                        " Subscribed_WeeklyDigest = @Subscribed_WeeklyDigest  " +
                        " WHERE (MemberId = @MemberId)";
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["membership"].ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@PreferedLanguage", member.PreferredLanguage.ToString());
                        cmd.Parameters.AddWithValue("@AgreedToSignUpTerms", member.AgreedToSignUpTerms);
                        cmd.Parameters.AddWithValue("@MobilePhoneNumber", member.MobilePhoneNumber != null ? member.MobilePhoneNumber : "");
                        cmd.Parameters.AddWithValue("@Subscribed_DailyDigest", member.Subscribed_DailyDigest);
                        cmd.Parameters.AddWithValue("@Subscribed_WeeklyDigest", member.Subscribed_WeeklyDigest);
                        cmd.Parameters.AddWithValue("@MemberId", member.MemberId);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException ex)
            {
                string msg = "Insert Error:";
                msg += ex.Message;
                //bg: I would like to log this, need to find that log method again.
                throw ex;
            }

            success = true;


            //push this up into salesforce... eventually....
            return success;
        }
        /// <summary>
        /// Fill the Member object with values from the database
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        private Member FillMember_ExtendedPropertiesFromDb(Member member)
        {
            try
            {
                string sql = " SELECT  PreferedLanguage, AgreedToSignUpTerms, MobilePhoneNumber " +
                             " FROM  dbo.Members " +
                             " WHERE (MemberId = @MemberId)";
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["membership"].ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@MemberId", member.MemberId);

                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                member.PreferredLanguage = reader.GetGuid(0);
                                member.AgreedToSignUpTerms = reader.GetBoolean(1);
                                if (!reader.IsDBNull(2))
                                {
                                    member.MobilePhoneNumber = reader.GetString(2) ?? string.Empty;
                                }
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            //add in member alert preferences
            try
            {
                string sql = " SELECT [SupportPlanReminders] " +
                            " ,[ObservationLogReminders] " +
                            " ,[EventReminders] " +
                            " ,[ContentReminders] " +
                            " ,[AdvocacyAlerts] " +
                            " ,[PrivateMessageAlerts] " +
                            " FROM [dbo].[MemberAlertPreferences] " +
                            " Where MemberId =@MemberId";
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["membership"].ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@MemberId", member.MemberId);

                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                member.SupportPlanReminders = reader.GetBoolean(0);
                                member.ObservationLogReminders = reader.GetBoolean(1);
                                member.EventReminders = reader.GetBoolean(2);
                                member.ContentReminders = reader.GetBoolean(3);
                                member.AdvocacyAlerts = reader.GetBoolean(4);
                                member.PrivateMessageAlerts = reader.GetBoolean(5);
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return member;
        }
        /// <summary>
        /// Used to inflate a member's quiz items and the responses that the user has saved to the db so far
        /// </summary>
        /// <param name="member">An inflated website Member</param>
        /// <returns>The same member, but now with quiz results.</returns>
        public Member QuizResults_FillMember(Member member)
        {
            string sql = "SELECT QuizId, QuestionId, AnswerValue " +
                " FROM  QuizResults " +
                " WHERE (MemberId = @MemberId) " +
                " ORDER BY QuizId"; //ordering by QuizId will let us loop through rows and know when to make a new Quiz object. 

            //each time we encounter a new quizid we need to populate a new set of quiz answers
            //default guid is a throw away
            Quiz quiz = new Quiz();
            quiz.QuizID = Guid.NewGuid();
            try
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["membership"].ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@MemberId", member.MemberId);
                        SqlDataReader reader = cmd.ExecuteReader();

                        if (reader.HasRows)
                        {
                            //first thing first. Clear out any existing items in the current member.
                            if (member.CompletedQuizes.Any())
                            {
                                member.CompletedQuizes.Clear();
                            }
                            bool firstrow = true;
                            while (reader.Read())
                            {
                                //see if we need a new quiz or of the existing quiz we are working with is still good.
                                if (quiz.QuizID != reader.GetGuid(0))// 0=QuizId. True when a new quiz is found. Always true for the first row.
                                {
                                    if (!firstrow)//dont add a filled quiz if this is the first read from the reader. New quiz id, but first quiz
                                    {
                                        //save the last quiz to the member
                                        member.CompletedQuizes.Add(quiz);//save the quiz that we were filling to the list.
                                    }
                                    else
                                    {
                                        firstrow = false;//this was the first row, now its not
                                    }
                                    quiz = new Quiz();//A new set of quiz answers was found. Setup a new quiz container
                                    quiz.QuizID = reader.GetGuid(0);// (0)=QuizId.
                                }
                                //every single row is always a new QuizItem
                                QuizItem quizItem = new QuizItem();
                                quizItem.QuestionId = reader.GetGuid(1);//(1)=QuestionId

                                //always check for nulls from a reader or it *will* eventually break.
                                if (!reader.IsDBNull(2))//(2)=AnswerValue
                                {
                                    quizItem.AnswerValue = reader.GetString(2);//(2)=AnswerValue
                                }
                                else
                                {
                                    quizItem.AnswerValue = string.Empty;
                                }
                                quiz.MemberAnswers.Add(quizItem);
                            }// * no matter what now, there is still a quiz that needs to still be added to member 
                            // * reader stops when there are no more rows to read, but we still haven't added the last quiz                            
                            member.CompletedQuizes.Add(quiz);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return member; //if the member had any quiz results in the db, it is now inflated with them

        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Connecting to salesforce");

            string fname = context.Request.QueryString["fname"];
            string lname = context.Request.QueryString["lname"];
            string email = context.Request.QueryString["email"];

            
            SalesforceManager sfMgr = new SalesforceManager("*****@*****.**", "8f9C3Ayq", "hlY0jOIILtogz3sQlLUtmERlu");
            if (sfMgr.LoggedIn)
            {
                //we are logged into salesforce.
                Member m = new Member();
                m.MemberId = Guid.NewGuid(); //adding in a random guid
                m.UserId = Guid.NewGuid(); //add in a random user id guid
                
                m.allowConnections = true;
                m.allowNewsletter = false ;
                m.emailSubscription = true;
                m.FirstName = fname;
                m.hasOtherChildren = false;
                m.isFacebookUser = true;
                m.isPrivate = true;
                m.LastName = lname;
                m.PersonalityType = new Guid("8B7EB70D-64B2-45B9-B06E-6AA5CB6FE983");//Optimisic Parent
              
                //m.Phone = 7811112222; //member phone & db need to be updated . int32 is too small for a phone number
               
                m.Role = new Guid("2BF9D7BE-2E40-432C-ADE7-A25C80B9B9EE");//Father
                
                Random random = new Random();
                int randomNumber = random.Next(0, 10000);
                m.ScreenName = "dummyuser_" + randomNumber.ToString();
                m.ZipCode = "01111";
                
                Journey j = new Journey();
                j.Key = new Guid( "0642E401-8E66-4C69-89C6-294C257456C8");
                j.Value = "Still Figuring it Out";
                m.Journeys.Add(j);

                Interest intr = new Interest();
                intr.Key = new Guid("110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9");
                intr.Value = "Assisted Living";
                m.Interests.Add(intr);

                Interest intr2 = new Interest();
                intr2.Key = new Guid("3C185099-76B4-49DD-80D4-A069A3F55FA1");
                intr2.Value = "Homework and Study Skills";
                m.Interests.Add(intr2);

                //setting up a couple of issues for children
                Issue issueOne = new Issue();
                issueOne.Key = new Guid("3390C210-0B22-48FD-A411-881F956EDC0C");
                issueOne.Value = "Listening";
                Issue issueTwo = new Issue();
                issueTwo.Key = new Guid("1D338D37-CF4E-4C1C-9499-EBA6C0A2BBA0");
                issueTwo.Value = "Math";

                //setting up a couple of diagnosis values for children
                Diagnosis d1 = new Diagnosis();
                d1.Key = new Guid("A66286A0-CD70-4FDD-9D13-9CF1C90EFC4A");
                d1.Value = "Receptive Language Disorder";
                Diagnosis d2 = new Diagnosis();
                d2.Key = new Guid("7A035CC2-D6BD-4332-9518-7AB22083F652");
                d2.Value = "ADHD";

                //setting up a couple of grade values for children
                Grade g1 = new Grade();
                g1.Key = new Guid("E26222FB-07CD-413B-9127-9050B6D2D037");
                g1.Value = "Grade 1";
                Grade g2 = new Grade();
                g2.Key = new Guid("E0B459C0-548A-4E6C-854A-E8F475416F12");
                g2.Value = "Grade 10";
              
                //setting up status values for children
                Guid iepStatus = new Guid("FBE464C6-0E52-45C5-A1E9-660CB3C6B688");//yes
                Guid section504Status = new Guid("55F38A58-7506-454E-95E5-0ECE22A3B99C");//in progress
                Guid evaluationStatus = new Guid("990FB117-F12E-4E3C-898B-8A9EB217FCFD");//yes
                //------------------------------------------
                //test child 1
                //------------------------------------------
                Child childOne = new Child();
                childOne.ChildId = Guid.NewGuid();//random new child guid for testing purposes
                childOne.Gender = "boy";
                childOne.Nickname = "Bobby";
                childOne.IEPStatus = iepStatus;
                childOne.Section504Status = section504Status;
                childOne.EvaluationStatus = evaluationStatus;

                childOne.Issues.Add(issueOne);
                childOne.Issues.Add(issueTwo);
                childOne.Grades.Add(g1);
                childOne.Diagnoses.Add(d1);
                childOne.Diagnoses.Add(d2);
                m.Children.Add(childOne); 
                //------------------------------------------
                //test child 2
                //------------------------------------------
                Child childTwo = new Child();
                childTwo.ChildId = Guid.NewGuid();//random new guid for testing
                childTwo.Gender = "boy";
                childTwo.Nickname = "Tommy";
                childTwo.IEPStatus = iepStatus;
                childTwo.Section504Status = section504Status;
                childTwo.EvaluationStatus = evaluationStatus;

                childTwo.Grades.Add(g2);
                childTwo.Issues.Add(issueOne);
                childTwo.Issues.Add(issueTwo);
                m.Children.Add(childTwo); 

                try
                {
                    SalesforceActionResult result = sfMgr.CreateWebsiteMemberAsContact(m,email);
                 
                    if (result.Success == true)
                    {
                        context.Response.Write(Environment.NewLine + "Contact (" + fname + " " + lname + ") is 'saved' to salesforce at: (" + sfMgr.SalesforceURL + ")"
                             + Environment.NewLine + "Message: " + result.Message );
                    }
                    else
                    {
                        context.Response.Write(Environment.NewLine + "Contact (" + fname + " " + lname + ") is not saved to salesforce at: (" + sfMgr.SalesforceURL + ")"
                            + Environment.NewLine + "Message: " + result.Message );
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(Environment.NewLine + "An error occured during in RunSalesfroceUpsert.ashx.cs " + 
                        Environment.NewLine + "Message: " +  ex.Message +
                        Environment.NewLine + "Stack Trace: " + ex.StackTrace);
                }                
            }
        }
        /// <summary>
        /// Adds a new member to the database
        /// </summary>
        /// <param name="Member">Member to add</param>
        /// <returns>Member that was added</returns>
        public Member AddMember(Member Member)
        {
            try
            {
                //using (_db)
                //{
                #region here lies crap that could work but looks like crap
                //var changes = new Dictionary<Guid, string>();

                //for (int i = 0; i < Member.Interests.Count; i++)
                //{
                //    var m = Member.Interests.ElementAt(i);
                //    m = this.GetInterest(m.Key);

                //    if (!changes.ContainsKey(m.Key))
                //    {
                //        db.Entry(m).State = EntityState.Unchanged;
                //        changes.Add(m.Key, m.Value);
                //    }

                //}

                //var interests = new List<Interest>();
                //var journeys = new List<Journey>();
                //var children = new List<Child>();


                //var tempMember = new Member();
                //tempMember.Interests = db.Interests.Where(i => Member.Interests.Contains) )

                //foreach (var item in Member.Interests)
                //{
                //    var t = this.GetInterest(item.Key);
                //    t.Members.Add(Member);

                //    interests.Add(t);
                //}

                //foreach (var item in Member.Journeys)
                //{
                //    var t = this.GetJourney(item.Key);
                //    t.Members.Add(Member);

                //    journeys.Add(t);
                //}

                //Member.Journeys.Clear();
                //Member.Interests.Clear();

                //foreach (var child in Member.Children)
                //{
                //for (int i = 0; i < child.Issues.Count; i++)
                //{
                //    var issue = child.Issues.ElementAt(i);
                //    issue = this.GetIssue(issue.Key);

                //    if (!changes.ContainsKey(issue.Key))
                //    {
                //        _db.Entry(issue).State = EntityState.Unchanged;
                //        changes.Add(issue.Key, issue.Value);                                
                //    }
                //}

                //var tempChild = new Child();

                ////issue mapping
                //foreach (var issue in child.Issues)
                //{
                //    var t = this.GetIssue(issue.Key);
                //    t.Children.Add(child);

                //    tempChild.Issues.Add(t);
                //}

                ////grade mapping
                //foreach (var grade in child.Grades)
                //{
                //    var t = this.GetGrade(grade.Key);
                //    t.Children.Add(child);

                //    tempChild.Grades.Add(t);
                //}

                ////diagnosis mapping
                //foreach (var diagnosis in child.Diagnoses)
                //{
                //    var t = this.GetDiagnosis(diagnosis.Key);
                //    t.Children.Add(child);

                //    tempChild.Diagnoses.Add(t);
                //}

                //children.Add(tempChild);

                //child.Issues.Clear();
                //child.Diagnoses.Clear();
                //child.Grades.Clear();
                //}

                //_db.Members.Add(Member);

                //foreach (var item in interests)
                //{
                //    db.Interests.Attach(item);
                //}

                //foreach (var item in journeys)
                //{
                //    db.Journeys.Attach(item);
                //}

                //foreach (var child in children)
                //{
                //    foreach (var issue in child.Issues)
                //    {
                //        db.Issues.Attach(issue);
                //    }

                //    foreach (var grade in child.Grades)
                //    {
                //        db.Grades.Attach(grade);
                //    }

                //    foreach (var diagnosis in child.Diagnoses)
                //    {
                //        db.Diagnoses.Attach(diagnosis);
                //    }
                //}
                #endregion

                var tMember = this.mapMember(Member);

                _db.Members.Add(tMember);
                _db.SaveChanges();
                //seed a row in the alert preferences table
                SeedMemberAlertPrefernceTable(tMember.MemberId);


                return tMember;
                //}
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var eve in ex.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw ex;
            }
        }
        /// <summary>
        /// Pass a populated Member in and it will update salesforce.
        /// </summary>
        /// <param name="newMember"></param>
        /// <returns>SalesforceSaveResult with success/fail bool & message if there was an error</returns>
        public SalesforceActionResult    CreateWebsiteMemberAsContact(Member newMember, string newMemberEmail) //member needs to be updated to have an email field
        {

            ////sf upserts have to happen in the proper order. upsert the member first
            //  each join / lookup value can be upsert after the member exists
            //  then we upsert child
            //  then we can upsert child lookup values

            SalesforceActionResult sfResult = new SalesforceActionResult();
            
            Contact newSalesforceContact = new Contact();
            //Created an account for Understood.org
            newSalesforceContact.AccountId = "001F0000014EhHtIAK"; //todo Move this and other similar values into a config
            
            //check required values
            if (string.IsNullOrEmpty(newMember.FirstName))
            {
                throw new Exception("First Name is required to save a new Contact Member to Service.");
            }
            else
            {
                newSalesforceContact.FirstName = newMember.FirstName;
                newSalesforceContact.member_FirstName__c = newMember.FirstName;
            }
            if (string.IsNullOrEmpty(newMember.LastName))
            {
                //last name will always be empty for now.
                //throw new Exception("Last Name is required to save a new Website Contact Member to Service.");
                newMember.LastName = "NotSpecified";
                newSalesforceContact.LastName = newMember.LastName;
                newSalesforceContact.member_LastName__c = newMember.LastName;
            }
            else
            {
                newSalesforceContact.LastName = newMember.LastName;
                newSalesforceContact.member_LastName__c = newMember.LastName;
            }
           
            newSalesforceContact.member_MemberId__c = newMember.MemberId.ToString(); //member_MemberId__c is our sfdc external uid on Contact
            newSalesforceContact.member_UserId__c = newMember.UserId.ToString();

            if (newMember.ScreenName == "Screen Name")//more garbage coming through
            {
                Random random = new Random();
                int randomNumber = random.Next(0, 30000);
                newMember.ScreenName = "ScreenName_" + randomNumber.ToString(); 
            }
            newSalesforceContact.member_ScreenName__c = newMember.ScreenName;

            //Discovered that if you do not set both the field, and the specififed field, you don't update the checkbocx
            newSalesforceContact.member_allowConnections__c = newMember.allowConnections;
            newSalesforceContact.member_allowConnections__cSpecified = newMember.allowConnections;

            newSalesforceContact.member_allowNewsletter__c = newMember.allowNewsletter;
            newSalesforceContact.member_allowNewsletter__cSpecified = newMember.allowNewsletter;

            newSalesforceContact.member_emailSubscription__c = newMember.emailSubscription;
            newSalesforceContact.member_emailSubscription__cSpecified = newMember.emailSubscription;

            newSalesforceContact.member_hasOtherChildren__c = newMember.hasOtherChildren;
            newSalesforceContact.member_hasOtherChildren__cSpecified = newMember.hasOtherChildren;

            newSalesforceContact.member_isFacebookUser__c = newMember.isFacebookUser;
            newSalesforceContact.member_isFacebookUser__cSpecified = newMember.isFacebookUser;

            newSalesforceContact.member_isPrivate__c = newMember.isPrivate;
            newSalesforceContact.member_isPrivate__cSpecified = newMember.isPrivate;
            
            newSalesforceContact.member_ZipCode__c = newMember.ZipCode;
            newSalesforceContact.Email = newMemberEmail;            

            //garbage is getting in still. 
            if (newMember.Role != new Guid("{00000000-0000-0000-0000-000000000000}"))
            {
                newSalesforceContact.member_Role__c = Constants.SalesforceLookupDictionary[newMember.Role];
            }
            
            //Journey may be null 
            if (newMember.Journeys.Count >= 1)
            {
                newSalesforceContact.Journey__c = Constants.SalesforceLookupDictionary[newMember.Journeys.First().Key];
            }
            
            //ContactsPersonality
            //THERE IS ALSO A PERSONALITYTYPE IN THE WSDL. DO NOT USE IT.
            if(!string.IsNullOrEmpty(newMember.PersonalityType.ToString()))
            {
                //garbage is getting in. skip garbage.
                if(newMember.PersonalityType != new Guid("{00000000-0000-0000-0000-000000000000}"))
                {
                    newSalesforceContact.member_Personality__c = Constants.SalesforceLookupDictionary[newMember.PersonalityType];//.ToString();
         
                }

            }
            //exernal id field name is not the value of the userid. its our guid for member. the name of the field/column in sfdc
            //sfdc needs to know the primary, unique key to look for when updating existing rows
            UpsertResult result = _sfs.upsert("member_MemberId__c", 
                                new sObject[] { newSalesforceContact })[0];
            string SalesforceNewContactId = string.Empty;

            if (result.success == false) //failed to create member. stop upserts. return.
            {

                sfResult.Success = false;
                sfResult.Message = "An error occured during the upsert to Salesforce." +
                    Environment.NewLine;
                foreach (Error e in result.errors)
                    sfResult.Message += "* " + e.message + Environment.NewLine;
                return sfResult;
            }
            else
            {
                SalesforceNewContactId = result.id ;// lets see if this was smart enough to update our contact 
            }
            //create entrires for Interests
            foreach (Interest i in newMember.Interests)
            {
                MemberToInterests__c sfdcMembertoInterest = new MemberToInterests__c();
                
                //i believe that I am going to need to get the ID of the user that was just created.
               // membertoInterest.MemberMaster__c = newMember.UserId.ToString();
                sfdcMembertoInterest.MemberMaster__c = SalesforceNewContactId; 
          
                //lookup the Salesforce Id from the Sitecore Guid
                sfdcMembertoInterest.MemberInterest__c = Constants.SalesforceLookupDictionary[i.Key];
                sfdcMembertoInterest.Name = i.Value;

                //NEED to use an exernal id for any upserted rows.... 
                //i think for masterdetail records we want to just do an INSERT
                SaveResult interestSaveResult = _sfs.create(new sObject[] { sfdcMembertoInterest })[0];
                if (interestSaveResult.success == false)
                {
                    sfResult.Success = false;
                    sfResult.Message = "An error occured during the upsert to Salesforce. Upserting Interest entries did not succeed." +
                        Environment.NewLine + "Error Messages: " + Environment.NewLine;
                    foreach (Error e in interestSaveResult.errors)
                    {
                        sfResult.Message += "Status code: (" + e.statusCode + ") Message: " + e.message + Environment.NewLine;
                    }
                    
                    return sfResult;
                 }
    
            }

            //add children to salesforce
            foreach (Child c in newMember.Children)
            {
                Children__c sfdcChild = new Children__c();
                sfdcChild.ContactChild__c = SalesforceNewContactId;
                sfdcChild.Grade__c = Constants.SalesforceLookupDictionary[(c.Grades.First().Key)];

                //these are blowing up with garbage values getting through
                if (c.Section504Status != new Guid("{00000000-0000-0000-0000-000000000000}"))
                {
                    sfdcChild.ChildTo504Status__c = Constants.SalesforceLookupDictionary[c.Section504Status];
                }
                if (c.EvaluationStatus != new Guid("{00000000-0000-0000-0000-000000000000}"))
                {
                   sfdcChild.ChildToEvaluationStatus__c = Constants.SalesforceLookupDictionary[c.EvaluationStatus];
                }
                if (c.IEPStatus != new Guid("{00000000-0000-0000-0000-000000000000}"))
                {
                    sfdcChild.ChildToIEPStatus__c = Constants.SalesforceLookupDictionary[c.IEPStatus];
                }
             
                sfdcChild.Nickname__c = c.Nickname;
                sfdcChild.Name = c.Nickname;
                
                //include a guid for the child's id
                sfdcChild.UnderstoodChildId__c = c.ChildId.ToString() ;
                SaveResult sfdcChildSaveResult = _sfs.create(new sObject[]{sfdcChild})[0];

                if(sfdcChildSaveResult.success == false)
                {
                    sfResult.Success = false;
                    sfResult.Message = "An error occured during the upsert to Salesforce. Upserting the Members Children did not succeed." +
                        Environment.NewLine + "Error Messages: " + Environment.NewLine;
                    foreach (Error e in sfdcChildSaveResult.errors)
                    {
                        sfResult.Message += "Status code: (" + e.statusCode + ") Message: " + e.message + Environment.NewLine;
                    }   
                    return sfResult;
                }
                //=====================================================================================================
             
                //with this child successfully created, we can now add rows to other objects that reference the child
                //get the new child's salesforce id and add in issues into the salesforce lookup object
                foreach (Issue childIssue in c.Issues)
                {
                    ChildToIssues__c sfdcforceChildIssues = new ChildToIssues__c();
                    sfdcforceChildIssues.ChildMaster__c = sfdcChildSaveResult.id; //we get back the ID that salesforce made during create
                    sfdcforceChildIssues.ChildIssue__c =Constants.SalesforceLookupDictionary[childIssue.Key];
                    sfdcforceChildIssues.Name = childIssue.Value;
                    SaveResult sr = _sfs.create(new sObject[] { sfdcforceChildIssues })[0];
                    if (sr.success == false)
                    {
                        sfResult.Success = false;
                        sfResult.Message = "An error occured during the upsert to Salesforce. Creating the Issues of Children did not succeed." +
                            Environment.NewLine + "Error Messages: " + Environment.NewLine;
                        foreach (Error e in sr.errors)
                        {
                            sfResult.Message += "Status code: (" + e.statusCode + ") Message: " + e.message + Environment.NewLine;
                        }
                        return sfResult;
                    }//-------------------
                    sfResult.Message= Environment.NewLine + 
                                                "Save Result for Issue (Name:" + sfdcforceChildIssues.Name + Environment.NewLine +
                                                                    "|Issue:" + sfdcforceChildIssues.ChildIssue__c + Environment.NewLine +
                                                                   " |Success:" + sr.success.ToString();                   
                }
                //save child diagnosis values
                foreach (Diagnosis childDiagnosis in c.Diagnoses)
                {
                    ChildToDiagnosis__c salesforceChildDiagnosis = new ChildToDiagnosis__c();
                    salesforceChildDiagnosis.ChildMaster__c = sfdcChildSaveResult.id;
                    salesforceChildDiagnosis.ChildDiagnosis__c = Constants.SalesforceLookupDictionary[childDiagnosis.Key];
                    salesforceChildDiagnosis.Name = childDiagnosis.Value;
                    SaveResult sr = _sfs.create(new sObject[] { salesforceChildDiagnosis })[0];
                    if (sr.success == false)
                    {
                        sfResult.Success = false;
                        sfResult.Message = "Error when saving child Diagnosis: " + sr.errors.First().message;
                        return sfResult;
                    }
                }
            }
            //          
            return sfResult;
        }
        public bool UpdateEmail(Member Member, string newEmail)
        {
            var ret = false;

            if (!string.IsNullOrEmpty(Member.Email) && !string.IsNullOrEmpty(newEmail))
            {
                try
                {
                    var provider = MembershipProvider.Providers[UnderstoodDotOrg.Common.Constants.MembershipProviderName];
                    var user = provider.GetUser(Member.MemberId, false);

                    //update username via stored procedure
                    ret = this.updateEmail(provider.ApplicationName, user.UserName, newEmail);

                    if (ret)
                    {
                        user = provider.GetUser(Member.MemberId, false);

                        user.Email = newEmail;

                        //update email property on ASP.Net user
                        provider.UpdateUser(user);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }

            return ret;
        }
        private void UpdateChild(Member member, Child child)
        {
            List<UnderstoodDotOrg.Domain.Search.Article> articles = Domain.Search.SearchHelper.GetArticles(member, child, _searchDate);

          

            //TEST CODE
            List<UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Base.BasePageItems.DefaultArticlePageItem> recommendedArticles;

            recommendedArticles = SearchHelper.GetRecommendedContent(member, UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Base.BasePageItems.DefaultArticlePageItem.TemplateId)
                                .Where(a => a.GetItem() != null)
                                .Select(a => new UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Base.BasePageItems.DefaultArticlePageItem(a.GetItem()))
                                .ToList();

            List<UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Pages.CommunityTemplates.Blogs.BlogsPostPageItem> recommendedBlogs;

            recommendedBlogs = SearchHelper.GetRecommendedContent(member, UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Pages.CommunityTemplates.Blogs.BlogsPostPageItem.TemplateId)
                                .Where(a => a.GetItem() != null)
                                .Select(a => new UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Pages.CommunityTemplates.Blogs.BlogsPostPageItem(a.GetItem()))
                                .ToList();

            //List<UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Base.BasePageItems.DefaultArticlePageItem> recommendedContent;

            //recommendedContent = SearchHelper.GetRecommendedContent(member, UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Base.BasePageItems.DefaultArticlePageItem.TemplateId)
            //                    .Where(a => a.GetItem() != null)
            //                    .Select(a => new UnderstoodDotOrg.Domain.SitecoreCIG.Poses.Base.BasePageItems.DefaultArticlePageItem(a.GetItem()))
            //                    .ToList();
            //END TEST CODE

            PersonalizationHelper.SavePersonalizedContent(member, child, articles);
        }
        public bool UpdatePassword(Member Member, string oldPassword, string newPassword)
        {
            var ret = false;

            var provider = MembershipProvider.Providers[UnderstoodDotOrg.Common.Constants.MembershipProviderName];
            var user = provider.GetUser(Member.MemberId, false);

            try
            {
                ret = user.ChangePassword(oldPassword, newPassword);
                
                if (!ret)
                {
                    //provided wrong password
                    throw new Exception("Password reset failed, please try again");
                }
            }
            catch (Exception ex)
            { 
                throw ex;
            }

            return ret;
        }
Ejemplo n.º 23
0
 public static string GetPublicProfileUrl(Member member)
 {
     return GetPublicProfileUrl(member.ScreenName);
 }
        /// <summary>
        /// Private method that maps a potentially Entity-disconnected Member to a known-connected instance
        /// </summary>
        /// <param name="Member">Potentially disconnected Member</param>
        /// <returns>Known connected Member</returns>
        private Member mapMember(Member Member)
        {
            var tMember = _db.Members.Where(x => x.MemberId == Member.MemberId).FirstOrDefault();

            if (tMember == null)
            {
                tMember = new Member();
                tMember.MemberId = Member.MemberId;
            }

            tMember.AgreedToSignUpTerms = Member.AgreedToSignUpTerms;
            tMember.allowConnections = Member.allowConnections;
            tMember.allowNewsletter = Member.allowNewsletter;
            tMember.emailSubscription = Member.emailSubscription;
            tMember.hasOtherChildren = Member.hasOtherChildren;
            tMember.isFacebookUser = Member.isFacebookUser;
            tMember.isPrivate = Member.isPrivate;
            tMember.PersonalityType = Member.PersonalityType;
            tMember.Role = Member.Role;
            tMember.ScreenName = Member.ScreenName.RemoveHTML();
            tMember.UserId = Member.UserId;

            if (!string.IsNullOrEmpty(Member.FirstName))
            {
                tMember.FirstName = Member.FirstName.RemoveHTML();
            }
            if (!string.IsNullOrEmpty(Member.LastName))
            {
                tMember.LastName = Member.LastName.RemoveHTML();
            }
            if (Member.Phone != null)
            {
                tMember.Phone = Member.Phone;
            }
            if (!string.IsNullOrEmpty(Member.ZipCode))
            {
                tMember.ZipCode = Member.ZipCode.RemoveHTML();
            }

            tMember.Interests.Clear();
            tMember.Journeys.Clear();

            foreach (var interest in Member.Interests)
            {
                var i = _db.Interests.Where(x => x.Key == interest.Key).FirstOrDefault();
                if (i != null)
                {
                    tMember.Interests.Add(i);
                }
            }

            foreach (var journey in Member.Journeys)
            {
                var j = _db.Journeys.Where(x => x.Key == journey.Key).FirstOrDefault();
                if (j != null)
                {
                    tMember.Journeys.Add(j);
                }
            }

            foreach (var child in Member.Children)
            {
                var tChild = mapChild(child);

                tMember.Children.Add(tChild);
            }

            return tMember;
        }
 public Member AddMember(Member Member, string Username, string Password)
 {
     return this.AddMember(Member);
 }
        /// <summary>
        /// Verifies credentials and process login for the user. Uses ASP.Net Membership for authentication and sets the Sitecore Virtual User
        /// </summary>
        /// <param name="Username">Email address of the user</param>
        /// <param name="Password">User's password</param>
        /// <returns>Returns an instance of the Member object filled with the current user, if authentication is successful</returns>
        public Member AuthenticateUser(string Username, string Password)
        {
            // use custom provider
            var provider = MembershipProvider.Providers[UnderstoodDotOrg.Common.Constants.MembershipProviderName];

            // authenticate against custom provider
            var isAuthenticated = provider.ValidateUser(Username, Password);
            if (!isAuthenticated)
            {
                throw new Exception("Invalid Username or Password");
            }

            // set SC virtual user

            // set Telligent user

            var membershipUser = provider.GetUser(Username, true);
            Member member = new Member();

            try
            {
                member = this.GetMember(Guid.Parse(membershipUser.ProviderUserKey.ToString()));
                if (member == null)
                {
                    throw new Exception("Membership User does not exist");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return member;
        }
 public Member UpdateMember(Member Member)
 {
     return this.GetMember(Guid.Empty);
 }
        /// <summary>
        /// Trims HTML and whitespace from Member string fields
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        public static Member trimFields(Member member)
        {
            member.FirstName = member.FirstName != null ? member.FirstName.Trim() : string.Empty;
            member.ScreenName = member.ScreenName != null ? member.ScreenName.Trim() : string.Empty;
            member.LastName = member.LastName != null ? member.LastName.Trim() : string.Empty;
            member.ZipCode = member.ZipCode != null ? member.ZipCode.Trim() : string.Empty;
            member.MobilePhoneNumber = member.MobilePhoneNumber != null ? member.MobilePhoneNumber.Trim() : string.Empty;

            return member;
        }
Ejemplo n.º 29
0
 public ContributorModel (Member m):base(m)
 {
     
 }
        /// <summary>
        /// It will help if we pull the data back from the db so we can display it and use it.
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        private Member FillMember_AlertPreferences(Member member)
        {
            string sql = " SELECT AdvocacyAlerts, " +
                                " ContentReminders, " +
                                " EventReminders, " +
                                " ObservationLogReminders, " +
                                " SupportPlanReminders, " +
                                " PrivateMessageAlerts " +
                                " FROM MemberAlertPreferences " +
                                " WHERE (MemberId = @MemberId)";
            try
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["membership"].ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@MemberId", member.MemberId);
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                member.AdvocacyAlerts = reader.GetBoolean(0);
                                member.ContentReminders = reader.GetBoolean(1);
                                member.EventReminders = reader.GetBoolean(2);
                                member.NotificationsDigest = false;//gotta check if this is in the db. bg: bug. think we might have dupe data
                                member.ObservationLogReminders = reader.GetBoolean(3);
                                member.SupportPlanReminders = reader.GetBoolean(4);
                                member.PrivateMessageAlerts = reader.GetBoolean(5);
                                //member.allowNewsletter; //set in entity

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return member;
        }