Beispiel #1
0
        public static TypeaheadResponse <TKey> GetForTypeahead <TItem, TKey>(
            this IQueryable <TItem> queryable,
            TypeaheadRequest <TKey> request,
            Expression <Func <TItem, TypeaheadItem <TKey> > > select,
            Expression <Func <TItem, bool> > getById,
            Expression <Func <TItem, bool> > getByQuery)
        {
            if (request.GetByIds)
            {
                var items = queryable.Where(getById).Select(select).ToList();
                return(new TypeaheadResponse <TKey>
                {
                    Items = items,
                    TotalItemCount = items.Count
                });
            }
            else
            {
                var items = queryable.Where(getByQuery).Select(select);

                return(new TypeaheadResponse <TKey>
                {
                    Items = items.Take(TypeaheadRequest <int> .ItemsPerRequest),
                    TotalItemCount = items.Count()
                });
            }
        }
Beispiel #2
0
        public static IEnumerable <object> GetTypeaheadSource <T>(this object source,
                                                                  MyFormHandler myFormHandler,
                                                                  TypeaheadRequest <T> request = null)
        {
            if (source is IEnumerable <object> )
            {
                return(source.CastTObject <IEnumerable <object> >());
            }
            if (request != null)
            {
                var list = new Dictionary <string, object> {
                    { "query", request.Query }, { "ids", request.Ids }
                };
                var obj = JsonConvert.SerializeObject(list);

                var dataSource  = source.ToString();
                var formRequest = new InvokeForm.Request
                {
                    Form             = dataSource,
                    InputFieldValues = obj
                };

                try
                {
                    var result = Task.Run(
                        () => myFormHandler.InvokeFormAsync(new[] { formRequest }));

                    var response = result.Result;

                    var typeahead = response[0].Data.CastTObject <TypeaheadResponse <object> >();

                    if (typeahead != null)
                    {
                        return(typeahead.Items);
                    }
                }
                catch (AggregateException ex)
                {
                    ex.ThrowInnerException();
                }
            }
            return(new List <object>());
        }