Пример #1
0
        private static void SeedBooks(BookShopSystemContext context)
        {
            int authorsCount = context.Authors.Local.Count;

            string[] books = File.ReadAllLines("../../Import/books.csv");

            for (int i = 1; i < books.Length; i++)
            {
                string[] data = books[i]
                                .Split(',')
                                .Select(arg => arg.Replace("\"", string.Empty))
                                .ToArray();

                int             authorIndex    = i % authorsCount;
                Author          author         = context.Authors.Local[authorIndex];
                EditionType     edition        = (EditionType)int.Parse(data[0]);
                DateTime        releaseDate    = DateTime.ParseExact(data[1], "d/M/yyyy", CultureInfo.InvariantCulture);
                int             copies         = int.Parse(data[2]);
                decimal         price          = decimal.Parse(data[3]);
                AgeRestrictions ageRestriction = (AgeRestrictions)int.Parse(data[4]);
                string          title          = data[5];
                Book            book           = new Book
                {
                    Type           = edition,
                    ReleaseData    = releaseDate,
                    Copies         = copies,
                    Price          = price,
                    AgeRestriction = ageRestriction,
                    Title          = title
                };

                context.Books.AddOrUpdate(b => new { b.Title, b.AuthorId }, book);
            }
        }
Пример #2
0
 public Book(string title, Editions edition, Author author, decimal price, int copies, AgeRestrictions ageRestriction, DateTime? releaseDate = null, string description = null)
 {
     this.Title = title;
     this.Description = description;
     this.Edition = edition;
     this.author = author;
     this.Price = price;
     this.Copies = copies;
     this.ReleaseDate = releaseDate;
     this.categories = new HashSet<Category>();
     this.AgeRestriction = ageRestriction;
     this.relatedBooks = new HashSet<Book>();
 }