Пример #1
0
        public static CFAContext GetContext()
        {
            //EffortProviderConfiguration.RegisterProvider();

            var        connection = DbConnectionFactory.CreateTransient();
            CFAContext context    = new CFAContext(connection, true);

            Database.SetInitializer(new DropCreateDatabaseAlways <CFAContext>());
            DataSeeder.SeedData(context);

            return(context);
        }
Пример #2
0
        protected override void Seed(CFAContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            //context.Roles.AddOrUpdate(role => role.Name,
            //    new Role { Key = Guid.NewGuid(), Name = "Admin" },
            //    new Role { Key = Guid.NewGuid(), Name = "Employee" },
            //    new Role { Key = Guid.NewGuid(), Name = "Affiliate" }
            //    );


            DataSeeder.SeedData(context);
        }
Пример #3
0
        public DbContextTest()
        {
            CFAContext context = Db.GetContext();

            _db = new Repository(context);
        }
Пример #4
0
        public static void SeedData(CFAContext _dbContext)
        {
            // add Action, Controller
            IRepository repository = new Repository(_dbContext);
            IQueryable <CFA.Domain.Entities.Action> existingActions = repository.GetAll <CFA.Domain.Entities.Action>();

            if (existingActions.IsEmpty())
            {
                IList <CFA.Domain.Entities.Action> actions = Seed.GetActions();
                repository.AddRange(actions);
                repository.Save();
            }

            IQueryable <Controller> existingControllers = repository.GetAll <Controller>();

            if (existingControllers.IsEmpty())
            {
                IList <Controller> controllers = Seed.GetControllers();
                repository.AddRange(controllers);
                repository.Save();
            }

            // add ControllerAction
            IQueryable <ControllerAction> existingControllerActions = repository.GetAll <ControllerAction>();

            if (existingControllerActions.IsEmpty())
            {
                IQueryable <Controller> addedControllers             = repository.GetAll <Controller>();
                IQueryable <CFA.Domain.Entities.Action> addedActions = repository.GetAll <CFA.Domain.Entities.Action>();
                IList <ControllerAction> controllerActions           = Seed.GetControllerActions(addedControllers, addedActions);
                repository.AddRange(controllerActions);
                repository.Save();
            }

            IQueryable <Right> existingRights = repository.GetAll <Right>();

            if (existingRights.IsEmpty())
            {
                IQueryable <ControllerAction> cas = repository.GetAll <ControllerAction>();
                IList <Right> rights = Seed.GetRights(cas);
                repository.AddRange(rights);
                repository.Save();
            }

            IQueryable <Role> existingRoles = repository.GetAll <Role>();

            if (existingRoles.IsEmpty())
            {
                IQueryable <Right> addedRights = repository.GetAll <Right>();
                IList <Role>       roles       = Seed.GetRoles(addedRights);
                repository.AddRange(roles);
                repository.Save();
            }

            IQueryable <User> existingUsers = repository.GetAll <User>();

            if (existingUsers.IsEmpty())
            {
                IList <Role> addedRoles = repository.GetAll <Role>().ToList();
                IList <User> users      = Seed.GetUsers(addedRoles);
                repository.AddRange(users);
                repository.Save();
            }

            IQueryable <PaymentChannel> existingPaymentChannels = repository.GetAll <PaymentChannel>();

            if (existingPaymentChannels.IsEmpty())
            {
                IList <PaymentChannel> paymentChannels = Seed.GetPaymentChannels();
                repository.AddRange(paymentChannels);
                repository.Save();
            }

            IQueryable <ProductType> existingProductTypes = repository.GetAll <ProductType>();

            if (existingProductTypes.IsEmpty())
            {
                IList <ProductType> productTypes = Seed.GetProductTypes();
                repository.AddRange(productTypes);
                repository.Save();
            }
        }