コード例 #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()
                    });
コード例 #2
0
        private static BookstoreDbContext CreateDatabase()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways <BookstoreDbContext>());
            var bookStoreDb = new BookstoreDbContext();

            bookStoreDb.Authors.Any();

            return(bookStoreDb);
        }
コード例 #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();
        }
コード例 #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");
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: mihmin98/proiect-daw
        // 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");
                }
            });
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: VladimirDimov/DataBases_HW
        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();
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: Startup.cs プロジェクト: keelyzglenn/Bookstore
        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();
        }
コード例 #9
0
 public GenericRepository(BookstoreDbContext _context)
 {
     this._context = _context;
     table         = _context.Set <T>();
 }
コード例 #10
0
 public Query(BookstoreDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext;
     _mapper    = mapper;
 }
コード例 #11
0
 public UserRepository(BookstoreDbContext context) : base(context)
 {
 }
コード例 #12
0
        private readonly ILogger <DbInitializer> logger; // Логирование в консоли

        public DbInitializer(BookstoreDbContext db, ILogger <DbInitializer> Logger)
        {
            this.db = db;
            logger  = Logger;
        }
コード例 #13
0
 public BookDbRepository(BookstoreDbContext _db)
 {
     db = _db;
 }
コード例 #14
0
 public BooksController(BookstoreDbContext _context)
 {
     context = _context;
 }
コード例 #15
0
 public AuthorDbRepository(BookstoreDbContext _db)
 {
     db = _db;
 }
コード例 #16
0
 public XmlParser(BookstoreDbContext context, ILogger logger)
 {
     this.BookstoreDb = context;
     this.Logger      = logger;
 }
コード例 #17
0
 public OrderService()
 {
     db = new BookstoreDbContext();
 }
コード例 #18
0
ファイル: ChuDeDAO.cs プロジェクト: kientrung0412/BookStore
 public ChuDeDAO()
 {
     DbContext = new BookstoreDbContext();
 }
コード例 #19
0
 public QueriesXmlParser(BookstoreDbContext context, ILogger logger, string outputFile)
     : base(context, logger)
 {
     this.rootElement    = new XElement("search-results");
     this.outputFilePath = outputFile;
 }
コード例 #20
0
 public AuthorDbRepository(BookstoreDbContext db)
 {
     this._db = db;
 }
コード例 #21
0
 public AuthorRepository(BookstoreDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #22
0
 public DealsRepository(BookstoreDbContext db) : base(db)
 {
 }
コード例 #23
0
 public RentalRepository(BookstoreDbContext context) : base(context)
 {
 }
コード例 #24
0
 public GroupService()
 {
     db = new BookstoreDbContext();
 }
コード例 #25
0
 public AccountService()
 {
     db = new BookstoreDbContext();
 }
コード例 #26
0
 public TransactionRepository(BookstoreDbContext context) : base(context)
 {
 }
コード例 #27
0
 public AuthorsController(BookstoreDbContext context)
 {
     _context = context;
 }
コード例 #28
0
 public WriterRepository(BookstoreDbContext bookstoreDb)
 {
     BookstoreDb = bookstoreDb;
 }