예제 #1
0
        static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();
            string provider         = config["DataProvider"],
                   connectionString = config["ConnectionString"];

            var optionsBuilder = new DbContextOptionsBuilder <BusinessDbContext>();

            optionsBuilder.UseMySql(connectionString);
            var reportingDbOptionsBuilder = new DbContextOptionsBuilder <ReservationDbContext>();

            reportingDbOptionsBuilder.UseMySql(connectionString);
            var identityAccessDbOptionsBuilder = new DbContextOptionsBuilder <IdentityAccessDbContext>();

            identityAccessDbOptionsBuilder.UseMySql(connectionString);
            var eventLogDbOptionsBuilder = new DbContextOptionsBuilder <IntegrationEventLogContext>();

            eventLogDbOptionsBuilder.UseMySql(connectionString);



            if (args.Length > 0)
            {
                connectionString = args[0];
            }

            // Use BusinessDbContext as entry point for dropping and recreating DB
            using (var context = new BusinessDbContext(optionsBuilder.Options))
            {
                if (context.Database.EnsureDeleted())
                {
                    context.Database.Migrate();
                }
            }

            DbContext[] contexts = new DbContext[] {
                new ReservationDbContext(reportingDbOptionsBuilder.Options),
                new IdentityAccessDbContext(identityAccessDbOptionsBuilder.Options),
                new IntegrationEventLogContext(eventLogDbOptionsBuilder.Options),
            };

            foreach (DbContext context in contexts)
            {
                context.Database.Migrate();

                context.Dispose();
            }
        }
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (actionContext.Request.Headers.Referrer != null)
            {
                var host = actionContext.Request.Headers.Referrer.Host;
                host = host.GetHostUrl();
                var split = host.Split('.');
                if (split.Length > 2)
                {
                    string tenancyName = split[0].ToLower();
                    Tenant tenant;

                    using (var db = new BusinessDbContext())
                    {
                        tenant = db.Tenants.AsNoTracking().FirstOrDefault(x => x.TenancyName.ToLower() == tenancyName);
                        db.Dispose();
                    }

                    if (tenant == null)
                    {
                        var response =
                            actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                                      "Sorry, '" + split[0].ToUpper() + "' is not registered to us.");
                        actionContext.Response = response;

                        Log.Error(actionContext.Response.ToString());
                    }
                    if (tenant != null && !tenant.Active || tenant != null && tenant.IsDeleted)
                    {
                        var response =
                            actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                                      "Sorry, '" + split[0].ToUpper() + "' is not registered to us.");
                        actionContext.Response = response;

                        Log.Error(actionContext.Response.ToString());
                    }
                }
            }



            base.OnActionExecuting(actionContext);
        }
 public void Dispose()
 {
     _db.Dispose();
 }
예제 #4
0
        //public int SaveChanges()
        //{
        //    return Db.SaveChanges();
        //}

        public void Dispose()
        {
            Db.Dispose();
            GC.SuppressFinalize(this);
        }
예제 #5
0
 public void Dispose()
 {
     _context?.Dispose();
 }