// Lucene.Net.Analysis.Standard.StandardAnalyzer.STOP_WORDS_SET ;

        /// <summary>
        /// Renders the Register View
        /// @Html.Action("RenderListUser","AprroveSurface");
        /// </summary>
        /// <returns></returns>
        /// called when link is pressed like prev and next page
        public ActionResult RenderAcl(PendingUserViewModel model)
        {
            bool hasloggedin = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            if (!hasloggedin)
            {
                return(PartialView("authsurface/notauth"));
            }

            //if the user in in the following role return unauthorized
            if (System.Web.HttpContext.Current.User.IsInRole("shiptraining") ||
                System.Web.HttpContext.Current.User.IsInRole("shipcounselor") ||
                System.Web.HttpContext.Current.User.IsInRole("shipstaff") ||
                System.Web.HttpContext.Current.User.IsInRole("partner")

                )
            {
                return(PartialView("authsurface/notauth"));
            }

            model.UsersView = searchPendingUsers(model);

            return(PartialView("approvesurface/userpendinglist", model));
        }
        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> searchPendingUsersOLD(PendingUserViewModel model)
        {
            List <UserView> users = 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..
            int intRoleAssigned = int.Parse(amember.GetValue("roleAssigned").ToString());

            string state = string.Empty; ////

            //request passes the state in the model.state

            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;
            }



            // var usrs = userService.GetMembersByPropertyValue("State", state);

            //@if( @Roles.IsUserInRole("StateAdmin"))
            var pageSize = 8;
            var page     = 1; int.TryParse(Request.QueryString["page"], out page);
            //var items = Model.Content.Children().Where(x => x.IsDocumentType("textpage")).OrderByDescending(x => x.CreateDate);
            //var date = DateTime.UtcNow.AddMinutes(-AppConstants.TimeSpanInMinutesToShowMembers);
            // var members = ApplicationContext.Current.Services.MemberService.GetMembersByPropertyValue(AppConstants.PropMemberLastActiveDate, date, ValuePropertyMatchType.GreaterThan)
            //                 .Where(x => x.IsApproved && !x.IsLockedOut);



            ////intRoleAssigned = 4; //RoleId
            var userList = userService.GetMembersByPropertyValue("RoleAppliedFor", intRoleAssigned, ValuePropertyMatchType.LessThanOrEqualTo).Where(x => !x.IsApproved);

            IEnumerable <Umbraco.Core.Models.IMember> items;

            if (state == "ALL")
            {
                items = userList.OrderBy(x => x.Properties["state"].Value.ToString());
            }
            else
            {
                items = userList.Where(x => x.Properties["state"].Value.ToString() == state);
            }


            //if the name is supplied filter by name
            if (!model.NameSearch.IsNullOrWhiteSpace())
            {
                items = items.Where(x => x.Name.ToLower().Contains(model.NameSearch.ToLower()));
            }


            //var itemse = userService.GetMembersByPropertyValue("State", state).Where(x => !x.IsApproved).OrderByDescending(x => x.Name);

            var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);

            if (page > totalPages)
            {
                page = totalPages;
            }
            else if (page < 1)
            {
                page = 1;
            }
            foreach (var auser in items)
            {
                //do not include the loggedin user..
                if (auser.Id != amember.Id)
                {
                    if (auser.GetValue("isDenied").ToString() != "1")
                    {
                        users.Add(
                            new UserView
                        {
                            ID = auser.Id.ToString(),
                            //Name = auser.Name,
                            Name  = auser.GetValue("firstName").ToString() + " " + auser.GetValue("lastName").ToString(),
                            Email = auser.Email,

                            CreatedDate = TryMyParse(auser.CreateDate.ToString()),
                            Status      = auser.GetValue("hasVerifiedEmail").ToString() == "0" ? "Waiting for Email Verification" : "Waiting for Approval",
                            State       = auser.GetValue("state").ToString()
                        }
                            );
                    }
                }
            }


            return(users);
        }