public ActionResult SearchResultsRead([DataSourceRequest] DataSourceRequest request)
        {
            EmployeeSearchAdditionalData employeeSearchAdditionalData = new EmployeeSearchAdditionalData();

            TryUpdateModel(employeeSearchAdditionalData);
            int searchType = FindSearchType(employeeSearchAdditionalData);

            if (searchType == 0)
            {
                return null;
            }

            string domain = ConfigurationManager.AppSettings["LDAPDomain"];
            string serviceUser = ConfigurationManager.AppSettings["ServiceUser"];
            string servicePassword = ConfigurationManager.AppSettings["ServicePassword"];

            LdapDirectoryIdentifier ldapDirectoryIdentifier = new LdapDirectoryIdentifier(domain);
            NetworkCredential myCredentials = new NetworkCredential(serviceUser, servicePassword);

            LdapConnection connection = new LdapConnection(ldapDirectoryIdentifier, myCredentials, AuthType.Basic);
            connection.SessionOptions.ProtocolVersion = 3;
            DirectoryContext context = new DirectoryContext(connection);

            var orders = context.Query<User>();

            switch (searchType)
            {
                case 1:
                    orders = orders.Where(u => (u.FirstName.Contains(employeeSearchAdditionalData.Keyword)) || (u.LastName.Contains(employeeSearchAdditionalData.Keyword)));
                    break;
                case 2:
                    orders = orders.Where(u => (u.CountryCode == employeeSearchAdditionalData.CountryCode1));
                    break;
                case 3:
                    orders = orders.Where(u => ((u.FirstName.Contains(employeeSearchAdditionalData.Keyword)) || (u.LastName.Contains(employeeSearchAdditionalData.Keyword)))
                        && (u.CountryCode == employeeSearchAdditionalData.CountryCode1));
                    break;
                case 4:
                    if(!String.IsNullOrWhiteSpace(employeeSearchAdditionalData.FirstName))
                    {
                        orders = orders.Where(u => (u.FirstName.Contains(employeeSearchAdditionalData.FirstName)));
                    }
                    if (!String.IsNullOrWhiteSpace(employeeSearchAdditionalData.LastName))
                    {
                        orders = orders.Where(u => (u.LastName.Contains(employeeSearchAdditionalData.LastName)));
                    }
                    if (!String.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode2))
                    {
                        orders = orders.Where(u => (u.CountryCode == employeeSearchAdditionalData.CountryCode2));
                    }
                    if (!String.IsNullOrWhiteSpace(employeeSearchAdditionalData.Location))
                    {
                        orders = orders.Where(u => (u.Location == employeeSearchAdditionalData.Location));
                    }
                    if (!String.IsNullOrWhiteSpace(employeeSearchAdditionalData.PositionTitle))
                    {
                        orders = orders.Where(u => (u.PositionTitle.Contains(employeeSearchAdditionalData.PositionTitle)));
                    }
                    if (!String.IsNullOrWhiteSpace(employeeSearchAdditionalData.FunctionalArea))
                    {
                        orders = orders.Where(u => (u.FunctionalArea == employeeSearchAdditionalData.FunctionalArea));
                    }
                    break;

            }

            orders = orders.Where(c => (c.Status == "Actif"));

            var total = orders.Count();

            orders = orders.ApplyOrdersSorting(request.Groups, request.Sorts);

            var x = orders.ApplyOrdersPaging(request.Page, request.PageSize, total);

            var result = new DataSourceResult()
            {
                Data = x,
                Total = total
            };

            return Json(result);
        }
        public int FindSearchType(EmployeeSearchAdditionalData employeeSearchAdditionalData)
        {
            //Blank
            if (
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Keyword) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode1) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FirstName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.LastName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode2) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Location) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.PositionTitle) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FunctionalArea)
                )
                return 0;
            //Keyword
            if (
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Keyword) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode1) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FirstName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.LastName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode2) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Location) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.PositionTitle) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FunctionalArea)
                )
                return 1;
            //Country
            if (
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Keyword) &&
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode1) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FirstName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.LastName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode2) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Location) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.PositionTitle) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FunctionalArea)
                )
                return 2;
            //Keyword and Country
            if (
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Keyword) &&
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode1) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FirstName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.LastName) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode2) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Location) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.PositionTitle) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FunctionalArea)
                )
                return 3;
            //First
            if (
                (string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Keyword) &&
                string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode1))  &&
                (
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FirstName) ||
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.LastName) ||
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.CountryCode2) ||
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.Location) ||
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.PositionTitle) ||
                !string.IsNullOrWhiteSpace(employeeSearchAdditionalData.FunctionalArea))
                )
                return 4;

            return 0;
        }