public static bool Where(this Entities.PublishingHouse publishingHouse, string namePattern) { if (publishingHouse == null) { throw new System.ArgumentNullException(nameof(publishingHouse)); } return(publishingHouse.Name.Contains(namePattern, System.StringComparison.OrdinalIgnoreCase)); }
public static bool Where(this Entities.PublishingHouse publishingHouse, Entities.Country country) { if (publishingHouse == null) { throw new System.ArgumentNullException(nameof(publishingHouse)); } if (country == null) { throw new System.ArgumentNullException(nameof(country)); } return(publishingHouse.Country == country); }
public static bool Has(this Entities.PublishingHouse publishingHouse, int?fromBookAmount, int?toBookAmount) { if (publishingHouse == null) { throw new System.ArgumentNullException(nameof(publishingHouse)); } bool has = true; int bookAmount = publishingHouse.Books.Count; if (fromBookAmount != null) { has &= bookAmount >= fromBookAmount.Value; } if (toBookAmount != null) { has &= bookAmount <= toBookAmount.Value; } return(has); }
// 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); }
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); }