public static void Main()
        {
            var db = new AppDbContext();
            var repo = new DbRepository<JokeCategory>(db);
            var categoriesService = new CategoriesService(repo);

            var configuration = Configuration.Default.WithDefaultLoader();
            var browsingContext = BrowsingContext.New(configuration);

            for (int i = 1; i <= 10000; i++)
            {
                var url = $"http://vicove.com/vic-{i}";
                var document = browsingContext.OpenAsync(url).Result;
                var jokeContent = document.QuerySelector("#content_box .post-content").TextContent.Trim();
                if (!string.IsNullOrWhiteSpace(jokeContent))
                {
                    var categoryName = document.QuerySelector("#content_box .thecategory a").TextContent.Trim();
                    var category = categoriesService.EnsureCategory(categoryName);
                    var joke = new Joke { Category = category, Content = jokeContent };
                    db.Jokes.Add(joke);
                    db.SaveChanges();
                    Console.WriteLine(i);
                }

            }
        }
Exemple #2
0
 public EditModel(App.Data.AppDbContext context,
                  UserManager <IdentityUser> userManager,
                  IAppRepository appRepository)
 {
     _context       = context;
     _userManager   = userManager;
     _appRepository = appRepository;
 }
        private static void InitializeAndSeedDb()
        {
            try
            {
                // Initializes and seeds the database.
                Database.SetInitializer(new DbInitializer());

                using (var context = new AppDbContext())
                {
                    context.Database.Initialize(force: true);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public SimpleMembershipInitializer()
        {
            Database.SetInitializer<AppDbContext>(null);

            try
            {
                using (var context = new AppDbContext())
                {
                    if (!context.Database.Exists())
                    {
                        // Create the SimpleMembership database without Entity Framework migration schema
                        ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                    }
                }

                WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfiles", "Id", "UserName", autoCreateTables: true);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
            }
        }
Exemple #5
0
 public DeleteModel(App.Data.AppDbContext context,
                    IAppRepository appRepository)
 {
     _context       = context;
     _appRepository = appRepository;
 }
 public AppDbContext Get()
 {
     return _dataContext ?? (_dataContext = new AppDbContext());
 }