/// <summary> /// CreateAsync /// </summary> /// <param name="model"></param> /// <param name="imagePath"></param> /// <param name="pdfPath"></param> /// <returns></returns> public async Task CreateAsync(CreateBookViewModel model, string imagePath, string pdfPath) { var book = new Entities.Book { Available = model.Available, Description = model.Description, Language = model.Language, Percent = model.Percent, Price = model.Price, Title = model.Title, AvailableCount = model.AvailableCount, CategoryId = model.CategoryId, HasPdf = pdfPath != null, PdfPath = pdfPath, ImagePath = imagePath, PagesNumber = model.PagesNumber, PublishYear = model.PublishYear, ISBN = model.ISBN }; await _context.Books.AddAsync(book); await _context.SaveChangesAsync(); var bookAuthors = new List <BookAuthor>(); foreach (var id in model.AuthorsId) { bookAuthors.Add(new BookAuthor { BookId = book.Id, AuthorId = id }); } await _context.BookAuthors.AddRangeAsync(bookAuthors); await _context.SaveChangesAsync(); }
public async Task <bool> HandleUseCase(int _request, IOutputPort <ResultDto <BookGetByIdOutputDto> > _presenter) { Entities.Book _book = await new BookSharedMethods(_bookRepository).GetBookItemIfValid(_request); _presenter.HandlePresenter(new ResultDto <BookGetByIdOutputDto>(_mapper.Map <BookGetByIdOutputDto>(_book))); return(true); }
public Entities.Book ChangeBook(Entities.Book newBook) { //var book = context.Books.FirstOrDefault(b => b.Id == newBook.Id); context.Books.Update(newBook); context.SaveChanges(); return(newBook); }
public async Task <Entities.Book> CreateBook(Entities.Book book) { if (_bookRepository.Any(v => v.Name == book.Name)) { throw new Exception("书名已存在"); } return(await _bookRepository.InsertAsync(book, true)); }
public void AddBook(Entities.Book bookToAdd) { if (bookToAdd == null) { throw new ArgumentNullException(nameof(bookToAdd)); } _booksContext.Add(bookToAdd); }
public static bool Where(this Entities.Book book, string namePattern) { if (book == null) { throw new System.ArgumentNullException(nameof(book)); } return(book.Name.Contains(namePattern, System.StringComparison.OrdinalIgnoreCase)); }
public async Task <bool> Handle(SaveBookCommand request, CancellationToken cancellationToken) { var inserted = false; var book = await _db.Books.FilterTitle(request.Title).FirstOrDefaultAsync(cancellationToken); if (book == null) { inserted = true; book = new Entities.Book(); } book.Title = request.Title; book.Language = request.Language; book.AuthorName = request.Author; if (request.Category != null) { var category = await _db.Categories.FirstOrDefaultAsync(x => x.Name == request.Category, cancellationToken); if (category == null) { category = new Entities.BookCategory { Name = request.Category }; } if (!book.Categories.Any(x => x.Category.Name == category.Name)) { book.Categories.Add(new Entities.BookCategoryBook() { Category = category }); } } if (inserted) { await _db.AddAsync(book, cancellationToken); } await _db.SaveChangesAsync(cancellationToken); var message = new UpdateBookEvent { Title = book.Title, Author = book.AuthorName, Language = book.Language }; await _bus.PublishAsync(ContextNames.Exchange.Book, message); return(true); }
public async Task <Chapter> CreateChapter(Entities.Book book, Volume volume, Chapter chapter) { if (volume.Chapters.Any(v => v.Title == volume.Title)) { return(chapter); } volume.AddChapter(chapter); await _bookRepository.UpdateAsync(book); return(chapter); }
public static bool Where(this Entities.Abonnement abonnement, Entities.Book book) { if (abonnement == null) { throw new System.ArgumentNullException(nameof(abonnement)); } if (book == null) { throw new System.ArgumentNullException(nameof(book)); } return(abonnement.Book == book); }
public Book(Entities.Book book) { Id = book.Id; Title = book.Title; Subtitle = book.Subtitle; Author = book.Author; PublishDate = book.PublishDate; Version = book.Version; PageNumber = book.PageNumber; PublishingHouse = book.PublishingHouse; ISBN = book.ISBN; CreatedAt = book.CreatedAt; UpdatedAt = book.UpdatedAt; }
private BookProxy MapEntityToProxy(Entities.Book e) { var ret = new BookProxy(); ret.Id = e.Id; ret.Title = e.Title; ret.Author = e.AuthorName; if (FeatureAddTableAtuthor.Get()) { ret.Author = e.Author?.Name; } ret.Language = e.Language; return(ret); }
public async Task <Volume> CreateVolume(Entities.Book book, Volume volume) { // book = await _bookRepository.FindAsync(b => b.Id == book.Id); // // if (book == null) // { // throw new Exception("Book不存在"); // } // // if (book.Volumes.Any(v => v.Title == volume.Title)) // { // throw new Exception("卷已存在"); // } // // book.AddVolume(volume); // await _bookRepository.UpdateAsync(book, true); return(volume); }
public IActionResult Edit(Book model) { try { Entities.Book book = new Entities.Book() { Author = model.Author, Id = model.Id, Name = model.Name }; uow.books.Put(book); uow.SaveChanges(); } catch (Exception) { //loglama } return(View(model)); }
public IActionResult Index(Book model) { Entities.Book book = new Entities.Book() { Name = model.Name, Author = model.Author }; try { uow.books.Post(book); uow.SaveChanges(); } catch (Exception) { // loglama } return(View()); }
public static bool Where(this Entities.Book book, int?fromBookAmount, int?toBookAmount) { if (book == null) { throw new System.ArgumentNullException(nameof(book)); } bool has = true; if (fromBookAmount != null) { has &= book.Amount >= fromBookAmount.Value; } if (toBookAmount != null) { has &= book.Amount <= toBookAmount.Value; } return(has); }
public async Task <IActionResult> Update(string isbn, Entities.Book book) { try { var bookItem = BookCatalogueContext.Books.Where(a => a.ISBN.Replace("-", "") == isbn.Replace("-", "")).FirstOrDefault(); if (bookItem != null) { var bookitem = BookCatalogueContext.Books .Where(c => c.ISBN == book.ISBN) .Include(u => u.Authors) .FirstOrDefault(); if (bookitem != null) { return(BadRequest("Record already exists")); } bookItem.Title = book.Title; bookItem.ISBN = book.ISBN; bookItem.Authors = new List <Author>(); bookItem.Authors.AddRange(book.Authors); await BookCatalogueContext.SaveChanges(); MessageSender sender = new MessageSender(); sender.SendMQ("Book Updated"); } else { return(NotFound()); } } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok()); }
public void SaveBook(Entities.Book book) { _service.SaveBook(book); }
public async Task RemoveBook(Entities.Book book) { await _bookRepository.DeleteAsync(book); }
public async Task UpdateBook(Entities.Book book) { await _bookRepository.UpdateAsync(book); }
// METHODS protected override void Seed(DataBaseContext context) { // COUNTRIES int countriesAmount = countriesList.Length; Entities.Country[] countries = new Entities.Country[countriesAmount]; for (int i = 0; i < countriesAmount; ++i) { countries[i] = new Entities.Country() { Name = countriesList[i] }; } context.Countries.AddRange(countries); // CATEGORIES int categoriesAmount = random.Next(10, 25); Entities.Category[] categories = new Entities.Category[categoriesAmount]; for (int i = 0; i < categoriesAmount; ++i) { categories[i] = new Entities.Category() { Name = words[random.Next(words.Length)] }; } context.Categories.AddRange(categories); // GENRES int genresAmount = random.Next(10, 25); Entities.Genre[] genres = new Entities.Genre[genresAmount]; for (int i = 0; i < genresAmount; ++i) { genres[i] = new Entities.Genre() { Name = words[random.Next(words.Length)] }; } context.Genres.AddRange(genres); // AUTHORS int authorsAmount = random.Next(50, 150); Entities.Author[] authors = new Entities.Author[authorsAmount]; for (int i = 0; i < authorsAmount; ++i) { authors[i] = new Entities.Author() { Name = words[random.Next(words.Length)], Surname = words[random.Next(words.Length)], Nickname = words[random.Next(words.Length)] + words[random.Next(words.Length)] }; } context.Authors.AddRange(authors); // PUBLISHING HOUSES int publishingHousesAmount = random.Next(20, 50); Entities.PublishingHouse[] publishingHouses = new Entities.PublishingHouse[publishingHousesAmount]; for (int i = 0; i < publishingHousesAmount; ++i) { publishingHouses[i] = new Entities.PublishingHouse() { Name = words[random.Next(words.Length)], Country = countries[random.Next(countriesAmount)], }; } context.PublishingHouses.AddRange(publishingHouses); // BOOK int booksAmount = random.Next(100, 500); Entities.Book[] books = new Entities.Book[booksAmount]; for (int i = 0; i < booksAmount; ++i) { books[i] = new Entities.Book() { Name = string.Join(" ", GenerateList(names, 1, 5)), Amount = random.Next(25, 50), Year = random.Next(1975, System.DateTime.Now.Year), Authors = GenerateList(authors, 1, 5), PublishingHouses = GenerateList(publishingHouses, 1, 3), Categories = GenerateList(categories, 1, 5), Genres = GenerateList(genres, 1, 5) }; } context.Books.AddRange(books); // READERS int readersAmount = random.Next(100, 500); Entities.Reader[] readers = new Entities.Reader[readersAmount]; for (int i = 0; i < readersAmount; ++i) { readers[i] = new Entities.Reader() { Name = names[random.Next(names.Length)], Surname = names[random.Next(names.Length)], Address = string.Join(" ", GenerateList(words, 1, 5)), Phone = GeneratePhoneNumber() }; } context.Readers.AddRange(readers); // ABONNEMENTS int abonnementsAmount = random.Next(1500, 5000); Entities.Abonnement[] abonnements = new Entities.Abonnement[abonnementsAmount]; for (int i = 0; i < abonnementsAmount; ++i) { System.DateTime takeDate = GenerateDate(); bool isReturned = random.Next(2) == 1; abonnements[i] = new Entities.Abonnement() { Reader = readers[random.Next(readers.Length)], Book = books[random.Next(books.Length)], TakeTime = takeDate, TakenPeriod = takeDate.AddDays(random.Next(7, 28)), ReturnTime = isReturned ? (System.DateTime?)takeDate.AddDays(random.Next(1, 20)) : null }; } context.Abonnements.AddRange(abonnements); base.Seed(context); }
public Entities.Book AddBookInCategory(Entities.Book newBook) { context.Books.Add(newBook); context.SaveChanges(); return(newBook); }
public Entities.Book Save(Entities.Book book) { return(_dal.GetBookRepository().Save(book)); }
public async Task SaveAsync(BookMessage model) { bool inserted = false; var book = await _db.Books.FilterTitle(model.Title).FirstOrDefaultAsync(); if (book == null) { inserted = true; book = new Entities.Book(); } book.Title = model.Title; book.Language = model.Language; if (model.Category != null) { var category = await _db.Categories.FirstOrDefaultAsync(x => x.Name == model.Category); if (category == null) { category = new Entities.BookCategory(); category.Name = model.Category; } if (!book.Categories.Any(x => x.Category.Name == category.Name)) { book.Categories.Add(new Entities.BookCategoryBook() { Category = category }); } } var authorName = model.Author; if (FeatureAddTableAtuthor.Get()) { book.Author = await _db.Authors.FirstOrDefaultAsync(x => x.Name == authorName); if (book.Author == null) { book.Author = new Entities.BookAuthor(); book.Author.Name = authorName; } } else { book.AuthorName = authorName; } if (inserted) { await _db.AddAsync(book); } else { _db.Update(book); } await _db.SaveChangesAsync(); var message = new BookUpdateMessage { Id = book.Id, Title = book.Title, Author = authorName, Language = book.Language }; await _bus.PublishAsync(ExchangeNames.Book, message); }
protected override void Seed(DataBaseContext context) { // COUNTRIES Entities.Country[] countries = new Entities.Country[] { new Entities.Country() { Name = "Albania" }, new Entities.Country() { Name = "Austria" }, new Entities.Country() { Name = "Canada" }, new Entities.Country() { Name = "Germany" }, new Entities.Country() { Name = "Italy" }, new Entities.Country() { Name = "Ukraine" } }; context.Countries.AddRange(countries); // CATEGORIES Entities.Category[] categories = new Entities.Category[] { new Entities.Category() { Name = "Novel" }, new Entities.Category() { Name = "Poems" } }; context.Categories.AddRange(categories); // GENRES Entities.Genre[] genres = new Entities.Genre[] { new Entities.Genre() { Name = "Fantasy" }, new Entities.Genre() { Name = "Mystery" }, new Entities.Genre() { Name = "Detective story" }, }; context.Genres.AddRange(genres); // AUTHORS Entities.Author[] authors = new Entities.Author[] { new Entities.Author() { Name = "Howard", Surname = "Lovecraft", Nickname = "Howard Phillips Lovecraft" }, new Entities.Author() { Name = "Stephen", Surname = "King", Nickname = "Stephen Edwin King" }, new Entities.Author() { Name = "Edgar", Surname = "Poe", Nickname = "Edgar Allan Poe" }, }; context.Authors.AddRange(authors); // PUBLISHING HOUSES Entities.PublishingHouse[] publishingHouses = new Entities.PublishingHouse[] { new Entities.PublishingHouse() { Name = "Wiley", Country = countries[0] }, new Entities.PublishingHouse() { Name = "Bertelsmann", Country = countries[3] }, new Entities.PublishingHouse() { Name = "Thomson Reuters", Country = countries[2] }, }; context.PublishingHouses.AddRange(publishingHouses); // BOOK Entities.Book[] books = new Entities.Book[] { new Entities.Book() { Name = "The Call of Cthulhu", Amount = 23, Year = 1995, Authors = new [] { authors[0] }, PublishingHouses = new Entities.PublishingHouse[] { publishingHouses[0] }, Categories = new Entities.Category[] { categories[0] }, Genres = new Entities.Genre[] { genres[0], genres[1] } }, new Entities.Book() { Name = "The Shining", Amount = 23, Year = 1993, Authors = new [] { authors[1] }, PublishingHouses = new Entities.PublishingHouse[] { publishingHouses[1] }, Categories = new Entities.Category[] { categories[0] }, Genres = new Entities.Genre[] { genres[1] } }, new Entities.Book() { Name = "It", Amount = 23, Year = 1978, Authors = new [] { authors[1] }, PublishingHouses = new Entities.PublishingHouse[] { publishingHouses[2] }, Categories = new Entities.Category[] { categories[0] }, Genres = new Entities.Genre[] { genres[1] } }, new Entities.Book() { Name = "The Raven", Amount = 23, Year = 1990, Authors = new [] { authors[2] }, PublishingHouses = new Entities.PublishingHouse[] { publishingHouses[0] }, Categories = new Entities.Category[] { categories[1] }, Genres = new Entities.Genre[] { genres[1] } }, }; context.Books.AddRange(books); // READERS Entities.Reader[] readers = new Entities.Reader[] { new Entities.Reader() { Name = "John", Surname = "Doe", Address = "Lorem Ipsum", Phone = "3809912345" }, new Entities.Reader() { Name = "Jane", Surname = "Doe", Address = "Dolor sit amet", Phone = "3809812345" }, }; context.Readers.AddRange(readers); // ABONNEMENTS Entities.Abonnement[] abonnements = new Entities.Abonnement[] { new Entities.Abonnement() { Reader = readers[0], Book = books[0], TakeTime = new System.DateTime(year: 2019, month: 2, day: 23), TakenPeriod = new System.DateTime(year: 2019, month: 2, day: 27) }, new Entities.Abonnement() { Reader = readers[1], Book = books[1], TakeTime = new System.DateTime(year: 2019, month: 2, day: 23), TakenPeriod = new System.DateTime(year: 2019, month: 2, day: 27), ReturnTime = new System.DateTime(year: 2019, month: 2, day: 25) }, new Entities.Abonnement() { Reader = readers[0], Book = books[2], TakeTime = new System.DateTime(year: 2019, month: 2, day: 23), TakenPeriod = new System.DateTime(year: 2019, month: 2, day: 27), ReturnTime = new System.DateTime(year: 2019, month: 2, day: 28) }, new Entities.Abonnement() { Reader = readers[0], Book = books[3], TakeTime = new System.DateTime(year: 2019, month: 2, day: 23), TakenPeriod = new System.DateTime(year: 2019, month: 2, day: 27) }, }; context.Abonnements.AddRange(abonnements); base.Seed(context); }