Exemplo n.º 1
0
        public static List <Search> Search(FindModel param)
        {
            IEnumerable <Search> result = new List <Search> {
                new Search()
                {
                    firstname = "Нет данных"
                }
            };

            if (param.TextSearch == String.Empty)
            {
                return(result.ToList());
            }

            int  sysid   = 0;
            bool isSysid = Int32.TryParse(param.TextSearch, out sysid);

            //если в строке число
            if (isSysid)
            {
                result = GetBySysid(sysid);
            }
            else

            //если диапазон
            if (param.TextSearch.Contains("-"))
            {
                result = GetIntervalSysid(param.TextSearch);
            }
            else
            //если список
            if (param.TextSearch.Contains(","))
            {
                result = GetListSysid(param.TextSearch);
            }
            else

            //если нет пробела
            if (!param.TextSearch.Contains(" "))
            {
                result = GetByName(param.TextSearch, param);
            }
            else

            //если два слова
            if (param.TextSearch.Contains(" "))
            {
                result = GetByNames(param.TextSearch, param);
            }


            return(result.ToList());
        }
Exemplo n.º 2
0
        private static IQueryable <Search> GetByName(string text, FindModel param)
        {
            IQueryable <Search> result;

            if (param.MatchEndings)
            {
                result = Context.Search.Where(x => (x.firstname.Contains(text) | x.lastname.Contains(text)));
            }
            else
            {
                result = Context.Search.Where(x => (x.firstname == text | x.lastname == text));
            }
            return(result);
        }
Exemplo n.º 3
0
        private static IEnumerable <Search> GetByNames(string text, FindModel param)
        {
            var name0 = HelpersFunction.GetStringsBySpace(text)[0];
            var name1 = HelpersFunction.GetStringsBySpace(text)[1];

            IQueryable <Search> result;

            if (param.MatchEndings)
            {
                result = Context.Search.Where(x => (x.firstname.Contains(name0) & x.lastname.Contains(name1))
                                              | (x.firstname.Contains(name1) & x.lastname.Contains(name0)));
            }
            else
            {
                result = Context.Search.
                         Where(x => (x.firstname == name0 & x.lastname == name1) | (x.firstname == name1 & x.lastname == name0));
            }
            return(result);
        }