コード例 #1
0
        public BookstoreQuery(AuthorRepository authorRepository, BookRepository bookRepository)
        {
            Field <ListGraphType <AuthorType> >("authors",
                                                arguments: new QueryArguments(
                                                    new QueryArgument <StringGraphType> {
                Name = "name"
            },
                                                    new QueryArgument <IntGraphType> {
                Name = "page", DefaultValue = 1
            },
                                                    new QueryArgument <IntGraphType> {
                Name = "pageSize", DefaultValue = 12
            }
                                                    ),
                                                resolve: context => {
                return(authorRepository.All(context));
            });
            Field <AuthorType>("author",
                               arguments: new QueryArguments(new QueryArgument <IdGraphType> {
                Name = "id"
            }),
                               resolve: context => {
                return(authorRepository.Find(context.GetArgument <long>("id")));
            });

            Field <ListGraphType <BookType> >("books",
                                              arguments: new QueryArguments(
                                                  new QueryArgument <StringGraphType> {
                Name = "name"
            },
                                                  new QueryArgument <StringGraphType> {
                Name = "description"
            },
                                                  new QueryArgument <FloatGraphType> {
                Name = "price"
            },
                                                  new QueryArgument <IntGraphType> {
                Name = "authorId"
            },
                                                  new QueryArgument <IntGraphType> {
                Name = "page", DefaultValue = 1
            },
                                                  new QueryArgument <IntGraphType> {
                Name = "pageSize", DefaultValue = 12
            }
                                                  ),
                                              resolve: context => {
                return(bookRepository.All(context));
            });
            Field <BookType>("book",
                             arguments: new QueryArguments(new QueryArgument <IdGraphType> {
                Name = "id"
            }),
                             resolve: context => {
                return(bookRepository.Find(context.GetArgument <long>("id")));
            });
        }
コード例 #2
0
        public void should_not_find_book_when_two_books_have_same_name()
        {
            var books = Builder <Book> .CreateListOfSize(2)
                        .All()
                        .With(x => x.Id               = 0)
                        .With(x => x.Author           = _author)
                        .With(x => x.AuthorMetadataId = _author.AuthorMetadataId)
                        .With(x => x.Title            = "Weezer")
                        .With(x => x.CleanTitle       = "weezer")
                        .Build();

            _bookRepo.InsertMany(books);

            var book = _bookRepo.FindByTitle(_author.AuthorMetadataId, "Weezer");

            _bookRepo.All().Should().HaveCount(4);
            book.Should().BeNull();
        }
コード例 #3
0
        public void should_not_find_album_when_two_albums_have_same_name()
        {
            var albums = Builder <Book> .CreateListOfSize(2)
                         .All()
                         .With(x => x.Id               = 0)
                         .With(x => x.Author           = _artist)
                         .With(x => x.AuthorMetadataId = _artist.AuthorMetadataId)
                         .With(x => x.Title            = "Weezer")
                         .With(x => x.CleanTitle       = "weezer")
                         .Build();

            _albumRepo.InsertMany(albums);

            var album = _albumRepo.FindByTitle(_artist.AuthorMetadataId, "Weezer");

            _albumRepo.All().Should().HaveCount(4);
            album.Should().BeNull();
        }
コード例 #4
0
        public object Get(BookModels request)
        {
            if (!string.IsNullOrEmpty(request.AmazonUrl))
            {
                try
                {
                    var response = BookParser.GetBookDetails(request.AmazonUrl);
                    return(response);
                }
                catch
                {
                }
            }

            if (request.Id > 0)
            {
                var book = BookRepository.Find(request.Id);
                book.Description = HttpContext.Current.Server.HtmlDecode(book.Description);

                return(book);
            }

            var books = new List <BookModels>();

            if (request.CategoryId <= 0)
            {
                var userAuth   = this.GetSession();
                var userAuthId = userAuth.Id.To <int>();

                books = BookRepository.All().Where(a => a.UserId == userAuthId && (request.CategoryId <= 0 || a.CategoryId == request.CategoryId)).ToList();
            }
            else
            {
                books = BookRepository.All().Where(a => request.CategoryId <= 0 || a.CategoryId == request.CategoryId).ToList();
            }

            foreach (var book in books)
            {
                book.CategoryText = LookupRepository.Find(book.CategoryId).Name;
                book.Description  = HttpContext.Current.Server.HtmlDecode(book.Description);
            }

            return(books);
        }
コード例 #5
0
 // GET: Units/Create
 public ActionResult Create()
 {
     ViewBag.BookID = new SelectList(bookRepository.All(), "ID", "Name");
     return(View());
 }
コード例 #6
0
        static void Main(string[] args)
        {
            var allBooks = new BookRepository().GetBooks();
            //PrintBooks(allBooks);

            var titles     = allBooks.Select(book => book.Title);
            var anonyTypes = allBooks.Select(book => new { Ttl = book.Title, Prc = book.Price });


            foreach (var anonyType in anonyTypes)
            {
                Console.WriteLine($"Title: {anonyType.Ttl}, Price: {anonyType.Prc}");
            }



            //var lessThan30RsBooks = allBooks.Where(book => FilterByPrice(book,30));
            var lessThan30RsBooks = allBooks.Where(book => book.Price < 30);

            if (allBooks.Any(book => book.Price > 30 && book.Author == "Mohit"))
            {
                Console.WriteLine("Hi Naina");
            }


            var firstBook = allBooks.First(book => book.Title.StartsWith("A"));

            var skippedFirst = allBooks.First(book => book.Title.StartsWith("A"));



            //Select  <--To choose a specific property from the collection and return the collection of the type of chosen property.
            //Where <- Filter the list and return the collection of the filtered items.
            //Any  <-- Returns true if any item is present in the list otherwise false.
            //First <-- Returns the first element of the list. If not item is present then throws exception with the message, "Sequence contains no elements" (InvalidOperationException)
            //Skip <-- Skips the number of elements specified in the params and returns the collection of remaining.
            //All  <-- Returns true/false after evaluating the specified condition on all the items of the list.


            if (allBooks.All(book => book.Price > 0))
            {
            }

            var highestPriceBook = allBooks.Skip(2).Max(book => book.Title);

            var booksOfEachPrice = allBooks.GroupBy(book => book.Price).Select(g => g.Skip(1).First());

            PrintBooks(booksOfEachPrice);

            /*var dict = new Dictionary<int, IEnumerable<Book>>();
             *
             * dict[10] = new List<Book> {null, null};
             * dict[20] = new List<Book> {null, null};
             * dict[30] = new List<Book> {null, null,null};*/

            var products = new List <Product>
            {
                new Mobile(),
                new Mobile(),
                new Laptop(),
                new XBox(),
                new XBox()
            };

            var mobiles   = products.OfType <Mobile>();
            var xboxes    = products.OfType <XBox>();
            var something = products.GroupBy(p => p.GetType() == typeof(Mobile)).First();
        }
コード例 #7
0
 // GET: Books
 public ActionResult Index()
 {
     return(View(bookRepository.All()));
 }
コード例 #8
0
 public object Get(SearchBooksViewModel request)
 {
     return(BookRepository.All().Where(a => (string.IsNullOrEmpty(request.Author) || a.Author.ToLowerInvariant().Contains(request.Author.ToLowerInvariant()))));
 }
コード例 #9
0
        public object Get(FeaturedBooksViewModel request)
        {
            var books = BookRepository.All().Where(a => a.IsFeature == true);

            return(books);
        }
コード例 #10
0
 public List <Book> All()
 {
     return(bookRepository.All());
 }