Пример #1
0
        public IActionResult ResetOrders()
        {
            Request.ThrowErrorIfNotLocal();

            _context.ResetOrders();
            SetupTraceInfo();
            return(View("BookUpdated", $"Successfully reset the customer orders."));
        }
Пример #2
0
        public static int SeedDatabase(this EfCoreContext context, string dataDirectory)
        {
            if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists())
            {
                throw new InvalidOperationException("The database does not exist. If you are using Migrations then run PMC command update-database to create it");
            }

            var numBooks = context.Books.Count();

            if (numBooks == 0)
            {
                //the database is emply so we fill it from a json file
                var books = BookJsonLoader.LoadBooks(Path.Combine(dataDirectory, SeedFileSubDirectory),
                                                     SeedDataSearchName).ToList();
                context.Books.AddRange(books);
                context.SaveChanges();
                numBooks = books.Count + 1;

                context.ResetOrders(books);
            }

            return(numBooks);
        }