private List <User> GetUsersByNameOrContain(string nameOrContain, UsersSearchParam searchParam)
        {
            StringComparison comparison = StringComparison.OrdinalIgnoreCase;

            switch (searchParam)
            {
            case UsersSearchParam.ByName: return(db.Users.ToList().FindAll((u) => u.Name.IndexOf(nameOrContain, comparison) == 0));

            case UsersSearchParam.IfContain: return(db.Users.ToList().FindAll((u) => u.Name.IndexOf(nameOrContain, comparison) >= 0));

            default: return(null);
            }
        }
Пример #2
0
        public async Task <IEnumerable <User> > GetUsersByNameOrContain(string nameOrContain, UsersSearchParam searchParam)
        {
            IEnumerable <User> users      = null;
            string             requestUri = String.Empty;

            switch (searchParam)
            {
            case UsersSearchParam.ByName: requestUri = path + "getbyname/" + nameOrContain;
                break;

            case UsersSearchParam.IfContain: requestUri = path + "getifcontain/" + nameOrContain;
                break;

            default: requestUri = path;
                break;
            }

            try
            {
                HttpResponseMessage response = await GetAsync(requestUri);

                if (response.IsSuccessStatusCode)
                {
                    users = await response.Content.ReadAsAsync <IEnumerable <User> >();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return(users);
        }