Esempio n. 1
0
 private static void CreateUser(PygmaDbContext dbContext, int id, string email, string firstname, string lastname, string role, bool active)
 {
     dbContext.Users.Add(new User()
     {
         Id        = id,
         FirstName = firstname,
         LastName  = lastname,
         Password  = "******",
         Role      = role,
         Active    = active,
         Email     = $"{email}@mymail.com"
     });
 }
Esempio n. 2
0
        public void Seed(PygmaDbContext dbContext)
        {
            dbContext.SetInsertIdentity("Users", true);

            CreateUser(dbContext, SeedConstants.AdminUser, "admin", "adminFirstname", "adminLastname", Roles.Admin, true);
            CreateUser(dbContext, SeedConstants.AuthorUser, "author", "authorFirstname", "authorLastname", Roles.Author, true);
            CreateUser(dbContext, SeedConstants.InActiveUser, "inactive", "-", "-", Roles.Author, false);

            dbContext.SaveChanges();

            dbContext.SetInsertIdentity("Users", false);

            dbContext.SaveChanges();
        }
Esempio n. 3
0
        public PygmaDbContext CreateContextForSqServer()
        {
            var connection = new SqlConnection("Server=.;Database=Pygma_Test;Integrated Security=SSPI");

            connection.Open();

            var option = new DbContextOptionsBuilder <PygmaDbContext>().UseSqlServer(connection).Options;

            var context = new PygmaDbContext(option);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            return(context);
        }
        public void Seed(PygmaDbContext dbContext)
        {
            dbContext.SetInsertIdentity("BlogPostComments", true);

            CreateBlogPostComment(dbContext, SeedConstants.PublishedComment1, "testVisitor_1",
                                  "My Test Comment 1", SeedConstants.PublishedBlogPost);
            CreateBlogPostComment(dbContext, SeedConstants.PublishedComment2, "testVisitor_2",
                                  "My Test Comment 2", SeedConstants.PublishedBlogPost);
            CreateBlogPostComment(dbContext, SeedConstants.InEditComment, "testVisitor_3",
                                  "My Test Comment 3", SeedConstants.InEditBlogPost);

            dbContext.SaveChanges();
            dbContext.SetInsertIdentity("BlogPostComments", false);
            dbContext.SaveChanges();
        }
 private static void CreateBlogPostComment(PygmaDbContext dbContext,
                                           int id,
                                           string visitorName,
                                           string comment,
                                           int blogPostId)
 {
     dbContext.BlogPostComments.Add(new Comment()
     {
         Id          = id,
         VisitorName = visitorName,
         CommentText = comment,
         BlogPostId  = blogPostId,
         CreatedAt   = DateTime.Now
     });
 }
Esempio n. 6
0
        public static void PopulateTestData(PygmaDbContext dbContext)
        {
            using var transaction = dbContext.Database.BeginTransaction();
            var seeding = new List <ISeeder>()
            {
                new UsersSeed(),
                new BlogPostSeed(),
                new BlogPostCommentSeed(),
            };

            foreach (var seeder in seeding)
            {
                seeder.Seed(dbContext);
            }

            dbContext.SaveChanges();
            transaction.Commit();
        }
Esempio n. 7
0
 private static void CreateBlogPost(PygmaDbContext dbContext,
                                    int id,
                                    int authorId,
                                    string title,
                                    string post,
                                    EnBlogPostStatus status,
                                    DateTime?publishedAt)
 {
     dbContext.BlogPosts.Add(new BlogPost()
     {
         Id          = id,
         AuthorId    = authorId,
         Title       = title,
         Post        = post,
         Status      = status,
         CreatedAt   = DateTime.Now,
         PublishedAt = publishedAt
     });
 }
Esempio n. 8
0
        public void Seed(PygmaDbContext dbContext)
        {
            dbContext.SetInsertIdentity("BlogPosts", true);

            CreateBlogPost(dbContext, SeedConstants.AdminBlogPost, SeedConstants.AdminUser,
                           "What is Lorem Ipsum",
                           "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
                           EnBlogPostStatus.Published, DateTime.Now);
            CreateBlogPost(dbContext, SeedConstants.AuthorBlogPost, SeedConstants.AuthorUser,
                           "Why do we use it",
                           "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).",
                           EnBlogPostStatus.Published, DateTime.Now);
            CreateBlogPost(dbContext, SeedConstants.InEditBlogPost, SeedConstants.AuthorUser,
                           "Where does it come from",
                           "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.",
                           EnBlogPostStatus.InEdit, null);

            dbContext.SaveChanges();

            dbContext.SetInsertIdentity("BlogPosts", false);

            dbContext.SaveChanges();
        }
Esempio n. 9
0
 public UsersRepository(PygmaDbContext context, IUsersCache usersCache) : base(context)
 {
     _context    = context;
     _usersCache = usersCache;
 }
 public BlogPostCommentsRepository(PygmaDbContext context) : base(context)
 {
 }
Esempio n. 11
0
 public static void SetInsertIdentity(this PygmaDbContext dbContext, string table, bool on)
 {
     dbContext.Database.ExecuteSqlRaw($"SET IDENTITY_INSERT {table} {(on ? "ON" : "OFF")};");
 }