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"))); }); }
private static void Main(string[] args) { using (var context = new rubenvh_boekenEntities()) using (var unitOfWork = new UnitOfWork()) using (var booksRepo = new BooksRepository(unitOfWork)) using (var categoriesRepo = new CategoryRepository(unitOfWork)) using (var authorsRepo = new AuthorRepository(unitOfWork)) { Console.WriteLine("Found {0} books.", context.boeken.Count()); var categories = categoriesRepo.All.ToList(); var allBooksQuery = context.boeken .Include(_ => _.Readings) .Include(_ => _.GenreLinks) .Include(_ => _.GenreLinks.Select(g => g.Genre)); var allBooks = allBooksQuery.ToList(); var authorDictionary = PrefillAuthors(allBooks, authorsRepo, unitOfWork); var newBooks = new List<Book>(allBooks.Count); foreach (var book in allBooks) { Console.WriteLine("Book {0} in {1}: {2}", book.boekID, book.GenreLinks.First().Genre.naam, book.Readings.Any() ? book.Readings.First().datum.ToString() : "not read"); newBooks.Add(new Book() { State = State.Added, FirstPublished = book.jaar.HasValue && book.jaar!=0? new DateTime(book.jaar.Value, 1, 1) : default(DateTime?), Isbn = book.isbn, Pages = book.blz ?? 0, Title = book.titel, Authors = new List<Author>() { authorsRepo.Find(authorDictionary[book.auteurs.ToLower()]) }, Readings = book.Readings.Select(_ => new Reading() { State = State.Added, PagesRead = book.blz ?? 0, Date = _.datum }).ToList(), CategoryId = categories.Single(_ => _.Name == book.GenreLinks.First().Genre.naam).Id, Tags = book.tags }); } newBooks.ForEach(booksRepo.InsertOrUpdateGraph); unitOfWork.Save(); } }
public BookType(AuthorRepository authorRepository) { Name = "Book"; Field(x => x.Id); Field(x => x.Name).Description("Name of the book"); Field(x => x.Description).Description("Description of the book"); Field(x => x.Price); Field(x => x.AuthorId); Field <AuthorType>( "author", resolve: context => { return(authorRepository.Find(context.Source.Id)); } ); }
public ActionResult Create(BookAuthorViewModel model) { if (ModelState.IsValid) { //if the UploadFile return null make the fileName empty string fileName = UploadFile(model.File) ?? string.Empty; try { // TODO: Add insert logic here if (model.AuthorId == -1) { ViewBag.message = "Please select an Author from the List"; return(View(GetAllAuthors())); } Book book = new Book { Id = model.BookId, Title = model.Title, Description = model.Description, Author = AuthorRepository.Find(model.AuthorId), ImageUrl = fileName }; BookRepository.Add(book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } } ModelState.AddModelError("", "Please Fill all required fildes"); return(View(GetAllAuthors())); }
public ActionResult Edit(int id, BookAuthorViewModel model) { try { //if the UploadFile return null make the fileName empty string fileName = UploadFile(model.File, model.ImageUrl); Book book = new Book { Id = model.BookId, Title = model.Title, Description = model.Description, Author = AuthorRepository.Find(model.AuthorId), ImageUrl = fileName }; BookRepository.Update(model.BookId, book); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public void FindTest() { var repository = new AuthorRepository(); repository.Find(1); }
public void Should_return_null_if_author_doesnt_exist() { var author = _authorRepository.Find(10); Assert.That(author, Is.Null); }
// GET: Authors/Details/5 public ActionResult Details(int id) { return(View(repo.Find(id))); }