private static void MigrateUserAssociation(MemberAssociation item) { var db1 = new SourceDbContext(); var db2 = new HostDbContext(); var member = db1.Members.FirstOrDefault(m => m.MemberId == item.MemberId); if (member != null) { var user = db2.User.FirstOrDefault(x => x.Phone == member.Phone.ToString()); var unit = db2.Units.FirstOrDefault(x => x.UnitId == item.UnitId); if (user != null && unit != null) { var isAssociated = db2.UserAssociation.FirstOrDefault(x => x.UnitId == unit.Id && x.IdUser == user.Id); if (isAssociated == null) { var ua = new UserAssociation { IdUser = user.Id, UnitId = unit.Id }; db2.UserAssociation.Add(ua); db2.SaveChanges(); } } } db1.Dispose(); db2.Dispose(); }
public Migration() { var jsonString = File.ReadAllText("database.json"); model = JsonSerializer.Deserialize <ConfigModel>(jsonString, JsonOptions); ctx1 = new SourceDbContext(model.SourceConfig.ConnectionString); ctx2 = new HostDbContext(model.HostConfig.ConnectionString); }
public UserSerivce(HostDbContext hostDbContext, MydbContext mydbContext, RoleManager <IdentityRole> roleManager, UserManager <IdentityUser> userManager) { _hostDbContext = hostDbContext; _userManager = userManager; _roleManager = roleManager; _mydbContext = mydbContext; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, HostDbContext context, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } var options = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >(); app.UseRequestLocalization(options.Value); // ana veritabanın kayıtları girilir HostDbContextInitializer.Initialize(context); // multi-tenancy kullanılmaya başlanılır app.UseMultitenancy <AppTenant>(); app.UseStaticFiles(); // üyelik sistemi devreye alınır // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "cultureRoute", template: "edux{app}/{culture}/{*slug}", defaults: new { controller = "Home", action = "Index", app = "centralpanel", culture = "no", slug = "giris" }, constraints: new { culture = new RegexRouteConstraint("^[a-z]{2}(?:-[A-Z]{2})?$") }); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, HostDbContext db) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // app.UseTenantInjector(); db.Database.EnsureCreated(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <ITenantResolver, TenantResolver>(); services.AddDbContext <HostDbContext>(options => { options.UseNpgsql(Configuration.GetConnectionString("HostConnection")); }); services.AddDbContext <MydbContext>((serviceProvider, dbContextBuilder) => { var connectionStringPlaceHolder = Configuration.GetConnectionString("PlaceHolderConnection"); var httpContextAccessor = serviceProvider.GetRequiredService <IHttpContextAccessor>(); HostDbContext hostDbContext = new HostDbContext(); //dbName = httpContextAccessor.HttpContext.Request.Headers["CURRENT_TENANT"].First(); var connectionString = ""; var OrganisationId = httpContextAccessor.HttpContext.Request.Headers["CURRENT_TENANT"].First(); Organisation organisation = hostDbContext.Organisations.Where(a => a.Id == Int32.Parse(OrganisationId)).FirstOrDefault(); // dbName = organisation.Name; connectionString = connectionStringPlaceHolder.Replace("{dbName}", organisation.Name); dbContextBuilder.UseNpgsql(connectionString); } ); // Identity FOR CORE DB services.AddIdentity <IdentityUser, IdentityRole>(options => { options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequiredLength = 5; }).AddEntityFrameworkStores <HostDbContext>(); /// TENANT DB services.AddIdentity <IdentityUser, IdentityRole>(options => { options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequiredLength = 5; }).AddEntityFrameworkStores <MydbContext>(); services.AddAuthentication(auth => { auth.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; auth.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuer = true, RequireExpirationTime = true, ValidateAudience = true, ValidAudience = Configuration["AuthSettings:Audience"], ValidIssuer = Configuration["AuthSettings:Issuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["AuthSettings:Key"])), ValidateIssuerSigningKey = true }; }); services.AddControllers(); }
public OrganisationController(HostDbContext Db) { _Db = Db; }
public CachingAppTenantResolver(HostDbContext dbContext, IMemoryCache cache, ILoggerFactory loggerFactory) : base(cache, loggerFactory) { _dbContext = dbContext; }
public AppTenantsController(HostDbContext context) { _context = context; }
public TenantsController(HostDbContext Db) { _Db = Db; }
public HostIdAndAuthCodeMustMatchRequirementHandler(IHttpContextAccessor httpContextAccessor, HostDbContext context, IConfiguration configuration) { _httpContextAccessor = httpContextAccessor; _context = context; _configuration = configuration; }