예제 #1
0
            public async Task <CQRSResult <List <BookGetDTO> > > Handle(BooksQuery request, CancellationToken cancellationToken)
            {
                var books = uow.BooksRepository.Get();

                return(mapper.Map <List <BookGetDTO> >(books));
                //return books.Select(x=> BookGetMap.ToDTO(x)).ToList();
            }
예제 #2
0
        private async Task <IEnumerable <Book> > GetBooksAsync(BooksQuery searchQuery)
        {
            var books = BooksQuery.GetBooksList();

            var list = searchQuery.GetListNames();

            books = FillBooksSelectedTimes(books, list);

            books.Sort((h1, h2) => h2.SelectedTimes.CompareTo(h1.SelectedTimes));

            return(books);
        }
예제 #3
0
        public async Task Invoke(HttpContext httpContext, ApplicationDbContext applicationContext)
        {
            var sent = false;

            if (httpContext.Request.Path.StartsWithSegments("/graph"))
            {
                using (var sr = new StreamReader(httpContext.Request.Body))
                {
                    var query = await sr.ReadToEndAsync();

                    if (!String.IsNullOrWhiteSpace(query))
                    {
                        BooksQuery bq     = new BooksQuery(applicationContext);
                        var        schema = new Schema {
                            Query = bq
                        };


                        if (httpContext.Request.Method == "OPTIONS")
                        {
                            var printedSchema = new SchemaPrinter(schema).Print();

                            await WriteResult(httpContext, printedSchema);

                            sent = true;
                        }
                        else
                        {
                            var result = await new DocumentExecuter()
                                         .ExecuteAsync(options =>
                            {
                                options.Schema = schema;
                                options.Query  = query;
                            }).ConfigureAwait(false);

                            CheckForErrors(result);

                            await WriteResult(httpContext, result);

                            sent = true;
                        }
                    }
                }
            }
            if (!sent)
            {
                await _next(httpContext);
            }
        }
예제 #4
0
        public IEnumerable <Book> GetFilteredBooks(BooksQuery query)
        {
            var books = context.Books.AsQueryable();

            if (query.EndYear.HasValue)
            {
                books = books.Where(book => book.Year <= query.EndYear);
            }
            if (query.StartYear.HasValue)
            {
                books = books.Where(book => book.Year >= query.StartYear);
            }
            if (!string.IsNullOrEmpty(query.Text))
            {
                books = books.Where(book => book.Title.Contains(query.Text));
            }

            return(books);
        }