public NoticeBoardDbContext CreateContext(DbTransaction transaction = null)
        {
            var context = new NoticeBoardDbContext
                              (new DbContextOptionsBuilder <NoticeBoardDbContext>()
                              .UseSqlServer(Connection)
                              .Options);

            if (transaction != null)
            {
                context.Database.UseTransaction(transaction);
            }
            return(context);
        }
Exemple #2
0
        private async Task Initialize(IServiceProvider serviceProvider,
                                      string adminPassword,
                                      string user1Password,
                                      string user2Password)
        {
            using (var context = new NoticeBoardDbContext(
                       serviceProvider.GetRequiredService <DbContextOptions <NoticeBoardDbContext> >()))
            {
                // The admin user can do anything

                var adminID = await EnsureUser(serviceProvider, adminPassword, _loginViewModels[0].Email);

                var user1ID = await EnsureUser(serviceProvider, user1Password, _loginViewModels[1].Email);

                var user2ID = await EnsureUser(serviceProvider, user2Password, _loginViewModels[2].Email);
                await EnsureRole(serviceProvider, adminID, NotificationConstants.ContactAdministratorsRole);

                //TODO:ensure more roles

                SeedDB(context, adminID, user1ID, user2ID);
            }
        }
Exemple #3
0
        private void SeedDB(NoticeBoardDbContext context, string adminID, string user1Id, string user2Id)
        {
            var Notifications = new Notification[]
            {
                new Notification()
                {
                    Name        = "I want to sell my car",
                    Description = "best car in the world, my number is 12345",
                    OwnerID     = adminID
                },
                new Notification
                {
                    Name        = "Test notification 2",
                    Description = " Test description for 2 notificaton.",
                    OwnerID     = adminID
                },
                new Notification
                {
                    Name        = "Apple MQAG2B/A iPhone X",
                    Description = "Get ready for a stunning experience with this Apple iPhone X smartphone.",
                    OwnerID     = user1Id
                },
                new Notification
                {
                    Name        = "Samsung Galaxy Note10 SM-N970U",
                    Description = "Samsung",
                    OwnerID     = user1Id
                },
                new Notification
                {
                    Name        = "Smartwatch Lenovo",
                    Description = "Smartwatch Lenovo HW10H BlazeMotorola.",
                    OwnerID     = user2Id
                }
            };

            if (!context.Notifications.Any())
            {
                context.Notifications.AddRange(Notifications);
                context.SaveChanges();
            }

            var Comments = new Comment[]
            {
                new Comment()
                {
                    OwnerID     = adminID,
                    Description = "Test comment for 0 notification content"
                },
                new Comment()
                {
                    OwnerID     = user1Id,
                    Description = "Test 1 comment for 0 notification content"
                },
                new Comment()
                {
                    OwnerID     = adminID,
                    Description = "Test 3 comment for 0 notification content"
                },
                new Comment()
                {
                    OwnerID     = user1Id,
                    Description = "Test 1 comment for 1 notification content"
                },
                new Comment()
                {
                    OwnerID     = adminID,
                    Description = "Test 2 comment for 1 notification content"
                },
                new Comment()
                {
                    OwnerID     = user2Id,
                    Description = "Test 1 comment for 2 notification content"
                }
            };

            if (!context.Comments.Any())
            {
                context.Comments.AddRange(Comments);
                context.SaveChanges();
            }
        }
 public NotificationsRepository(NoticeBoardDbContext context)
     : base(context)
 {
 }
Exemple #5
0
 public CommentsRepository(NoticeBoardDbContext context)
     : base(context)
 {
 }
 public GenericRepository(NoticeBoardDbContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = _dbContext.Set <TEntity>();
 }