protected override void Up(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <SiriusContext>();

            string connectionString = "Host=127.0.0.1;Port=5432;Database=siriusdb;Username=siriususer;Password=Uncle340571578;Integrated Security=false;";

            var options = optionsBuilder
                          .UseNpgsql(connectionString)
                          .Options;

            using (var context = new SiriusContext(options))
            {
                Role adminRole = new Role {
                    Id = DefaultValues.Roles.Admin.Id, Name = "Администратор"
                };
                Role viewerRole = new Role {
                    Id = DefaultValues.Roles.Viewer.Id, Name = "Просмотр"
                };
                context.Roles.AddRange(new Role[] { adminRole, viewerRole });

                /*
                 * User admin = context.Users.Where(user => user.FirstName == "Администратор").FirstOrDefault();
                 * if (admin != null)
                 * {
                 *  admin.Role = adminRole;
                 *  admin.RoleId = adminRole.Id;
                 *  context.Users.Update(admin);
                 * }*/
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(SiriusContext.Create);
            app.CreatePerOwinContext <SiriusUserManager>(SiriusUserManager.Create);
            app.CreatePerOwinContext <SiriusSignInManager>(SiriusSignInManager.Create);
            app.CreatePerOwinContext <SiriusRoleManager>(SiriusRoleManager.Create);

            Database.SetInitializer <SiriusContext>(new MigrateDatabaseToLatestVersion <SiriusContext, Sirius.Data.Migrations.Configuration>());
            SiriusContext context = new SiriusContext();

            context.Database.Initialize(false);

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "ApplicationCookie",
                LoginPath          = new PathString("/user/login"),
                ExpireTimeSpan     = TimeSpan.FromHours(3)
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <SiriusContext>();

            string connectionString = "Host=127.0.0.1;Port=5432;Database=siriusdb;Username=siriususer;Password=Uncle340571578;Integrated Security=false;";

            var options = optionsBuilder
                          .UseNpgsql(connectionString)
                          .Options;

            using (var context = new SiriusContext(options))
            {
                Role viewerRole = context.Roles.Where(role => role.Id == DefaultValues.Roles.Viewer.Id).FirstOrDefault();

                var startDate = DateConverter.ConvertToRTS(DateTime.UtcNow.ToLocalTime());

                byte[] passwordHash, passwordSalt;
                PasswordHash.CreatePasswordHash("user2019", out passwordHash, out passwordSalt);

                var user = new User {
                    FirstName    = "Пользователь",
                    LastName     = "",
                    Username     = "******",
                    Id           = Guid.NewGuid(),
                    Role         = viewerRole,
                    StartDate    = startDate,
                    IsConfirmed  = true,
                    PasswordHash = passwordHash,
                    PasswordSalt = passwordSalt
                };

                context.Users.Add(user);
                context.SaveChanges();
            }
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <SiriusContext>();

            string connectionString = "Host=127.0.0.1;Port=5432;Database=siriusdb;Username=siriususer;Password=Uncle340571578;Integrated Security=false;";

            var options = optionsBuilder
                          .UseNpgsql(connectionString)
                          .Options;

            using (var context = new SiriusContext(options))
            {
                Role adminRole = context.Roles.Where(role => role.Id == DefaultValues.Roles.Admin.Id).FirstOrDefault();
                //User admin = context.Users.Where(user => user.FirstName == "Администратор").FirstOrDefault();
                var users = context.Users.ToArray();
                foreach (var user in users)
                {
                    user.Role = adminRole;
                    context.Users.Update(user);
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
 public RegisterRepository(SiriusContext _siriusContext) : base(_siriusContext)
 {
 }
Exemplo n.º 6
0
 public BaseRepository(SiriusContext context)
 {
     dbContext = context;
     _dbset    = context.Set <T>();
 }
Exemplo n.º 7
0
 public SiriusContext Init()
 {
     return(dbContext ?? (dbContext = new SiriusContext()));
 }
Exemplo n.º 8
0
 public UserRepository(SiriusContext context) : base(context)
 {
 }
Exemplo n.º 9
0
 public ItemRepository(SiriusContext _siriusContext) : base(_siriusContext)
 {
 }
Exemplo n.º 10
0
 public RoleRepository(SiriusContext _siriusContext) : base(_siriusContext)
 {
 }
Exemplo n.º 11
0
 public InvoiceRepository(SiriusContext _siriusContext) : base(_siriusContext)
 {
 }
Exemplo n.º 12
0
 public SettingRepository(SiriusContext context) : base(context)
 {
 }