Ejemplo n.º 1
0
        public static void Seed(this BookstoreDbContext context)
        {
            if (!context.Role.Any())
            {
                context.Add(new Role {
                    Name = "Admin"
                });
                context.Add(new Role {
                    Name = "User"
                });
                context.SaveChanges();
            }

            if (!context.User.Any())
            {
                var adminUser = new User
                {
                    Email     = "*****@*****.**",
                    FirstName = "Admin",
                    LastName  = "Admin",
                    Username  = "******",
                    Password  = "******"
                };

                context.Add(adminUser);

                context.SaveChanges();

                if (!context.UserRoleMapping.Any())
                {
                    context.UserRoleMapping.Add(new UserRoleMapping {
                        UserId = adminUser.Id, RoleId = context.Role.FirstOrDefault(x => x.Name == "Admin")?.Id ?? throw new InvalidOperationException()
                    });
Ejemplo n.º 2
0
        private static BookstoreDbContext CreateDatabase()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways <BookstoreDbContext>());
            var bookStoreDb = new BookstoreDbContext();

            bookStoreDb.Authors.Any();

            return(bookStoreDb);
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture =
                System.Globalization.CultureInfo.InvariantCulture;

            Console.WriteLine("USE . !!!");
            Console.WriteLine();
            db = new BookstoreDbContext();
            Import();
            //Search();
        }
Ejemplo n.º 4
0
        private static void Main()
        {
            BookstoreDbContext dbContext = CreateDatabase();

            BooksXmlParser booksParser = new BooksXmlParser(dbContext, new ConsoleLogger());

            booksParser.Parse("../../../complex-book.xml");

            QueriesXmlParser queriesParser = new QueriesXmlParser(dbContext, new ConsoleLogger(), "../../../reviews-search-results.xml");

            queriesParser.Parse("../../../reviews-queries.xml");
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BookstoreDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            dbContext.Database.EnsureCreated();

            //app.UseCors("AllowAll");
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();
            app.UseCors(builder =>
            {
                builder.AllowAnyOrigin();
                builder.AllowAnyMethod();
                builder.AllowAnyHeader();
            });

            app.UseMiddleware <JwtMiddleware>();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Ejemplo n.º 6
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<BookstoreDbContext, Configuration>());

            var db = new BookstoreDbContext();

            db.Authors.Count();

            var xmlController = new XmlController<CatalogXml>();
            var books = xmlController.Deserialize(XmlInputPath).Books;

            foreach (var book in books)
            {
                var authors = new List<Author>();
                if (book.Authors != null)
                {
                    foreach (var auth in book.Authors)
                    {
                        authors.Add(new Author() { Name = auth });
                    }
                }

                var reviews = new List<Review>();

                if (book.Reviews != null)
                {
                    foreach (var review in book.Reviews)
                    {
                        reviews.Add(new Review()
                        {
                            Author = new Author() { Name = review.Author == null ? null : review.Author },
                            CreationDate = review.Date != null ? DateTime.Parse(review.Date) : DateTime.MinValue
                        });
                    }
                }

                var bookToAdd = db.Books.Add(new Book()
                {
                    Title = book.Title,
                    Isbn = book.Isbn,
                    Price = book.Price,
                    WebSite = book.Website
                });

                bookToAdd.Reviews = reviews;
                bookToAdd.Authors = authors;

                db.Books.Add(bookToAdd);
            }

            db.SaveChanges();
        }
        static void Main(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookstoreDbContext>();

            optionsBuilder.UseSqlServer(ConnectionString);

            var context = new BookstoreDbContext(optionsBuilder.Options);

            context.Database.Migrate();

            var saeedGanji = Author.Create("Saeed", "Ganji", new DateTime(1985, 1, 1));

            context.Authors.Add(saeedGanji);
            context.SaveChanges();

            //
            // context.Database.Migrate();
            // context.Database.EnsureCreated();
            //
            // var me = Author.Create("Saeed", "Ganji", DateTime.Now.AddDays(-1));
            // me.AddBook("EF Core" , "132465");
            //
            // var other = Author.Create("John", "Doe", DateTime.Now.AddDays(-1));
            // other.AddBook("No Idea", "132465");
            //
            // context.Authors.AddRange(me,other);
            //
            // context.SaveChanges();

            Author me = null;

            // mention AsNoTracking in the article
            me = context.Authors.AsNoTracking().FirstOrDefault(x => x.FirstName == "Saeed");
            me.AddBook("SampleBook", "1234567-890");

            context.SaveChanges();

            Console.WriteLine(context.Entry(me).Property("CreatedOn").CurrentValue);
        }
Ejemplo n.º 8
0
        private static void AddTestData(BookstoreDbContext context)
        {
            context.Database.ExecuteSqlCommand("Delete From Books");

            var book1 = new Book();

            book1.Title  = "Anna Karenina";
            book1.Author = "Leo Tolstoy";
            context.Books.Add(book1);

            var book2 = new Book();

            book2.Title  = "Into the Wildnerness";
            book2.Author = "Sarah Donati";
            context.Books.Add(book2);

            var book3 = new Book();

            book3.Title  = "Harry Potter, Chamber of Secrets";
            book3.Author = "JK Rowling";
            context.Books.Add(book3);

            context.SaveChanges();
        }
Ejemplo n.º 9
0
 public GenericRepository(BookstoreDbContext _context)
 {
     this._context = _context;
     table         = _context.Set <T>();
 }
 public Query(BookstoreDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext;
     _mapper    = mapper;
 }
Ejemplo n.º 11
0
 public UserRepository(BookstoreDbContext context) : base(context)
 {
 }
        private readonly ILogger <DbInitializer> logger; // Логирование в консоли

        public DbInitializer(BookstoreDbContext db, ILogger <DbInitializer> Logger)
        {
            this.db = db;
            logger  = Logger;
        }
Ejemplo n.º 13
0
 public BookDbRepository(BookstoreDbContext _db)
 {
     db = _db;
 }
Ejemplo n.º 14
0
 public BooksController(BookstoreDbContext _context)
 {
     context = _context;
 }
Ejemplo n.º 15
0
 public AuthorDbRepository(BookstoreDbContext _db)
 {
     db = _db;
 }
Ejemplo n.º 16
0
 public XmlParser(BookstoreDbContext context, ILogger logger)
 {
     this.BookstoreDb = context;
     this.Logger      = logger;
 }
Ejemplo n.º 17
0
 public OrderService()
 {
     db = new BookstoreDbContext();
 }
Ejemplo n.º 18
0
 public ChuDeDAO()
 {
     DbContext = new BookstoreDbContext();
 }
Ejemplo n.º 19
0
 public QueriesXmlParser(BookstoreDbContext context, ILogger logger, string outputFile)
     : base(context, logger)
 {
     this.rootElement    = new XElement("search-results");
     this.outputFilePath = outputFile;
 }
Ejemplo n.º 20
0
 public AuthorDbRepository(BookstoreDbContext db)
 {
     this._db = db;
 }
Ejemplo n.º 21
0
 public AuthorRepository(BookstoreDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public DealsRepository(BookstoreDbContext db) : base(db)
 {
 }
Ejemplo n.º 23
0
 public RentalRepository(BookstoreDbContext context) : base(context)
 {
 }
Ejemplo n.º 24
0
 public GroupService()
 {
     db = new BookstoreDbContext();
 }
Ejemplo n.º 25
0
 public AccountService()
 {
     db = new BookstoreDbContext();
 }
Ejemplo n.º 26
0
 public TransactionRepository(BookstoreDbContext context) : base(context)
 {
 }
Ejemplo n.º 27
0
 public AuthorsController(BookstoreDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 28
0
 public WriterRepository(BookstoreDbContext bookstoreDb)
 {
     BookstoreDb = bookstoreDb;
 }