private int CountPendingUsers()
        {
            bool hasloggedin = (System.Web.HttpContext.Current.User != null) &&
                               System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            var    userService = Services.MemberService;
            string usern       = string.Empty;

            usern = System.Web.HttpContext.Current.User.Identity.Name;


            //UmbracoShipTac.Code.UiEnum.RolesId.shipcounselor

            var amember = userService.GetByEmail(usern);

            //get the rolid of the  user.. from the isinrole
            string strRoleAssigned = amember.GetValue("roleAssigned").ToString();

            string state = string.Empty;

            state = amember.GetValue("state").ToString();



            // Use the already configured member searcher
            var memberSearcher = ExamineManager.Instance
                                 .SearchProviderCollection["InternalMemberSearcher"]
                                 .CreateSearchCriteria(BooleanOperation.Or);

            Examine.SearchCriteria.IBooleanOperation filter = null;
            filter = memberSearcher.Field("hasVerifiedEmail", "0"); //just to start a dummy this is OR ? I think It is AND
            filter = filter.And().Field("umbracoMemberApproved", "0");



            if (state.ToUpper() != "ALL")
            {
                filter = filter.And().Field("state", state);
            }


            filter = filter.And().Range("roleAppliedFor", "1", strRoleAssigned, true, true);

            filter = filter.And().Field("isDenied", "0");

            ISearchResults resultsAllMembers = ExamineManager.Instance
                                               .SearchProviderCollection["InternalMemberSearcher"]
                                               .Search(filter.Compile());


            int pendingusers = resultsAllMembers.Count();

            //do not include the loggedin user..
            // if (id != amember.Id.ToString())

            return(pendingusers);
        }
        private List <UserView> searchPendingUsers(PendingUserViewModel model)
        {
            List <UserView> users = new List <UserView>();

            List <UserView> sortedList = new List <UserView>();

            bool hasloggedin = (System.Web.HttpContext.Current.User != null) &&
                               System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            var    userService = Services.MemberService;
            string usern       = string.Empty;

            usern = System.Web.HttpContext.Current.User.Identity.Name;


            //UmbracoShipTac.Code.UiEnum.RolesId.shipcounselor

            var amember = userService.GetByEmail(usern);

            //get the rolid of the  user.. from the isinrole
            string strRoleAssigned = amember.GetValue("roleAssigned").ToString();

            string state = string.Empty;

            if (!String.IsNullOrWhiteSpace(model.State))
            {
                state = model.State;
            }
            else
            {
                state = amember.GetValue("state").ToString();
                //set the modele state with correcte value of state.
                model.State = state;
            }


            //all OR then and ..to work in lucene index
            if (state.ToUpper() == "OR" || state.ToUpper() == "IN")
            {
                //do the old way of searching..
                ////  return searchPendingUsersOLD(model);
            }


            // Use the already configured member searcher
            var memberSearcher = ExamineManager.Instance
                                 .SearchProviderCollection["InternalMemberSearcher"]
                                 .CreateSearchCriteria(BooleanOperation.Or);

            Examine.SearchCriteria.IBooleanOperation filter = null;
            filter = memberSearcher.Field("hasVerifiedEmail", "0"); //just to start a dummy this is OR ? I think It is AND
            filter = filter.And().Field("umbracoMemberApproved", "0");



            //if the name is supplied filter by name
            if (!model.NameSearch.IsNullOrWhiteSpace())
            {
                //filter = filter.And().Field("firstName", model.NameSearch);
                filter = filter.And().GroupedOr(new string[] { "firstName", "lastName" }, model.NameSearch);
            }

            if (state.ToUpper() != "ALL")
            {
                filter = filter.And().Field("state", state);
            }


            filter = filter.And().Range("roleAppliedFor", "1", strRoleAssigned, true, true);

            filter = filter.And().Field("isDenied", "0");

            ISearchResults resultsAllMembers = ExamineManager.Instance
                                               .SearchProviderCollection["InternalMemberSearcher"]
                                               .Search(filter.Compile());

            // Execute the query and get back search results
            // ISearchResults resultsAllMembers = memberSearcher.Search(allMembersCriteria);

            // Iterate through the results
            // Fields is a dictionary where the key is the property type alias and the value is a string
            foreach (var member in resultsAllMembers)
            {
                var fname = member.Fields.ContainsKey("firstName") ? member.Fields["firstName"] : "";
                //member.Fields["firstName"];
                var lname = member.Fields.ContainsKey("lastName") ? member.Fields["lastName"] : "";
                //member.Fields["lastName"];
                var id = member.Fields["id"];

                var appDate = member.Fields.ContainsKey("dateApproved") ? member.Fields["dateApproved"] : "";

                var denDate = member.Fields.ContainsKey("dateDenied") ? member.Fields["dateDenied"] : "";


                var updateDate = member.Fields.ContainsKey("updateDate") ? member.Fields["updateDate"] : "";


                var state1 = member.Fields.ContainsKey("state") ? member.Fields["state"] : "";

                var email = member.Fields.ContainsKey("email") ? member.Fields["email"] : "";



                string roleValue = member.Fields.ContainsKey("roleAssigned") ? member.Fields["roleAssigned"] : "";

                string isDenied         = member.Fields.ContainsKey("isDenied") ? member.Fields["isDenied"] : "";
                string isInactive       = member.Fields.ContainsKey("isInactive") ? member.Fields["isInactive"] : "";
                string hasVerifiedEmail = member.Fields.ContainsKey("hasVerifiedEmail") ? member.Fields["hasVerifiedEmail"] : "";
                string IsApproved       = member.Fields.ContainsKey("umbracoMemberApproved") ? member.Fields["umbracoMemberApproved"] : "";

                //do not include the loggedin user..
                if (id != amember.Id.ToString())
                {
                    users.Add(
                        new UserView
                    {
                        ID          = id,
                        Name        = fname + " " + lname,
                        Email       = email,
                        CreatedDate = TryMyParse(updateDate),

                        Status = Utils.GetUserStatus(isDenied, isInactive, hasVerifiedEmail, IsApproved),
                        State  = state1
                                 //Status = auser.GetValue("hasVerifiedEmail").ToString() == "0" ? "Waiting for Email Verification" : "Waiting for Approval",
                    }
                        );
                }
            }

            //sort it by LastLoginDate this is the default..
            sortedList = users.OrderBy(o => o.LastLoginDate).ToList();

            return(sortedList);
        }
        private List <UserView> searchApprovedUsers(UserViewModel model)
        {
            List <UserView> users = new List <UserView>();

            List <UserView> sortedList = new List <UserView>();

            bool hasloggedin = (System.Web.HttpContext.Current.User != null) &&
                               System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            var    userService = Services.MemberService;
            string usern       = string.Empty;

            usern = System.Web.HttpContext.Current.User.Identity.Name;


            //UmbracoShipTac.Code.UiEnum.RolesId.shipcounselor

            var amember = userService.GetByEmail(usern);

            //get the rolid of the  user.. from the isinrole
            string strRoleAssigned = amember.GetValue("roleAssigned").ToString();

            string state = string.Empty;

            if (!String.IsNullOrWhiteSpace(model.State))
            {
                state = model.State;
            }
            else
            {
                state = amember.GetValue("state").ToString();
                //set the modele state with correcte value of state.
                model.State = state;
            }


            //all OR then and ..to work in lucene index
            if (state.ToUpper() == "OR" || state.ToUpper() == "IN")
            {
                //add a blank"

                //model.State = " "          + state;
                //do the old way of searching..
                // return searchApprovedUsersOLD(model);
            }


            // Use the already configured member searcher
            var memberSearcher = ExamineManager.Instance
                                 .SearchProviderCollection["InternalMemberSearcher"]
                                 .CreateSearchCriteria(BooleanOperation.Or);

            //did not work
            //  memberSearcher.SearchIndexType.RemoveStopWords();

            Examine.SearchCriteria.IBooleanOperation filter = null;
            filter = memberSearcher.Field("hasVerifiedEmail", "1"); //just to start a dummy this is OR



            //if the name is supplied filter by name
            if (!model.NameSearch.IsNullOrWhiteSpace())
            {
                //filter = filter.And().Field("firstName", model.NameSearch);
                //  filter = filter.And().GroupedOr(new string[] { "firstName", "lastName" }, model.NameSearch );


                //this makes a OR but giving OR results
                filter = filter.And().GroupedOr(new string[] { "firstName", "lastName" }, model.NameSearch.ToLower().MultipleCharacterWildcard());
            }


            filter = filter.And().Range("roleAppliedFor", "1", strRoleAssigned, true, true);
            filter = filter.And().Field("state", state);



            // Lucene.Net.Analysis.StopAnalyzer.ENGLISH_STOP_WORDS_SET = new System.Collections.Hashtable();

            ISearchResults resultsAllMembers = ExamineManager.Instance
                                               .SearchProviderCollection["InternalMemberSearcher"]
                                               .Search(filter.Compile());

            // Execute the query and get back search results
            // ISearchResults resultsAllMembers = memberSearcher.Search(allMembersCriteria);

            // Iterate through the results
            // Fields is a dictionary where the key is the property type alias and the value is a string
            foreach (var member in resultsAllMembers)
            {
                var fname = member.Fields.ContainsKey("firstName") ? member.Fields["firstName"] : "";
                //member.Fields["firstName"];
                var lname = member.Fields.ContainsKey("lastName") ? member.Fields["lastName"] : "";
                //member.Fields["lastName"];
                var id = member.Fields["id"];

                var appDate = member.Fields.ContainsKey("dateApproved") ? member.Fields["dateApproved"] : "";

                var denDate = member.Fields.ContainsKey("dateDenied") ? member.Fields["dateDenied"] : "";


                var lastDate = member.Fields.ContainsKey("lastLoggedIn") ? member.Fields["lastLoggedIn"] : "";


                var state1 = member.Fields.ContainsKey("state") ? member.Fields["state"] : "";


                string roleValue = member.Fields.ContainsKey("roleAssigned") ? member.Fields["roleAssigned"] : "";

                string isDenied         = member.Fields.ContainsKey("isDenied") ? member.Fields["isDenied"] : "";
                string isInactive       = member.Fields.ContainsKey("isInactive") ? member.Fields["isInactive"] : "";
                string hasVerifiedEmail = member.Fields.ContainsKey("hasVerifiedEmail") ? member.Fields["hasVerifiedEmail"] : "";
                string IsApproved       = member.Fields.ContainsKey("umbracoMemberApproved") ? member.Fields["umbracoMemberApproved"] : "";

                //do not include the loggedin user..
                if (id != amember.Id.ToString())
                {
                    users.Add(
                        new UserView
                    {
                        ID            = id,
                        Role          = GetUserRoleByValue(roleValue),
                        Name          = fname + " " + lname,
                        ApprovedDate  = appDate,
                        DeniedDate    = denDate,
                        LastLoginDate = lastDate,
                        Status        = Utils.GetUserStatus(isDenied, isInactive, hasVerifiedEmail, IsApproved)
                    }
                        );
                }
            }

            //sort it by LastLoginDate this is the default..
            sortedList = users.OrderBy(o => o.LastLoginDate).ToList();

            return(sortedList);
        }
        //TODO: add correct search criteria
        //year  month and roleBased
        private List <EventResult> SearchEvents(int month, int year)
        {
            //the resource will be searched only for the logged in users

            List <EventResult> results = new List <EventResult>();

            // Find pages that contain our search text in either their nodeName or bodyText fields...
            // but exclude any pages that have been hidden.
            // searchCriteria.Fields("nodeName",terms.Boost(8)).Or().Field("metaTitle","hello".Boost(5)).Compile();

            //if nothing selected return null result
            //if (model.ResTerm.IsNullOrWhiteSpace()
            //    && model.SelectedFileTypes == null
            //    && model.SelectedSubjects == null
            //    && model.SelectedAudences == null
            //    && model.SelectedActivities == null
            //    && model.State.IsNullOrWhiteSpace())
            //{
            //    return results;
            //}

            if (User.Identity.IsAuthenticated)
            {
                string[] roles = System.Web.Security.Roles.GetRolesForUser(User.Identity.Name);

                //Event search

                var criteriaEventRestricted = ExamineManager.Instance
                                              .SearchProviderCollection["EventSearcher"]
                                              .CreateSearchCriteria(BooleanOperation.Or);

                Examine.SearchCriteria.IBooleanOperation filter = null;


                filter = criteriaEventRestricted.Field("IsPublic", "false"); //just to start a dummy this is OR

                filter = filter.And().Field("roles", roles[0]);
                filter = filter.And().Field("eventmonth", month.ToString());
                filter = filter.And().Field("eventyear", year.ToString());

                //add date and month
                //filter = filter.And().Field()

                //if (model.ResTerm != null && model.ResTerm.Length > 0)
                //    filter = filter.And().GroupedOr(new string[] { "description", "eventtitle", "nodeName", "name", "seo", "intendedaudiences"}, model.ResTerm);



                ISearchResults SearchResults = ExamineManager.Instance
                                               .SearchProviderCollection["EventSearcher"]
                                               .Search(filter.Compile());


                foreach (var sr in SearchResults)
                {
                    EventResult result = new EventResult()
                    {
                        Id        = sr.Fields.ContainsKey("id") ? sr.Fields["id"] : "",
                        Url       = Umbraco.Content(sr.Fields["id"]).Url,
                        NodeName  = sr.Fields.ContainsKey("nodeName") ? sr.Fields["nodeName"] : "",
                        Text      = sr.Fields.ContainsKey("description") ? sr.Fields["description"] : "",
                        sdtTime   = sr.Fields.ContainsKey("datetimefrom") ? sr.Fields["datetimefrom"] : "",
                        sdtTimeTo = sr.Fields.ContainsKey("datetimeto") ? sr.Fields["datetimeto"] : "",
                    };

                    result.Text = result.Text.Substring(0, Math.Min(result.Text.Length, 250));


                    DateTime myDate;
                    if (DateTime.TryParse(result.sdtTime, out myDate))
                    {
                        result.day      = myDate.Day;
                        result.month    = myDate.Month;
                        result.year     = myDate.Year;
                        result.timeFrom = myDate.ToShortTimeString();
                    }
                    else
                    {
                        // handle parse failure
                    }

                    DateTime myDateTo;
                    if (DateTime.TryParse(result.sdtTimeTo, out myDateTo))
                    {
                        result.timeTo = myDateTo.ToShortTimeString();
                    }
                    else
                    {
                        // handle parse failure
                    }



                    results.Add(result);
                }
            }


            return(results);
        }