public virtual object Clone() { var result = MemberwiseClone() as AssetEntry; result.Tenant = Tenant?.Clone() as TenantIdentity; result.BlobInfo = BlobInfo?.Clone() as BlobInfo; return(result); }
public static bool CreateTenant(MasterUserSession tenantUserSession, Tenant tenant, out Tenant tenantMaster, out Exception exception) { var result = false; Tenant tenantMasterTemp = null; exception = null; tenantMaster = null; try { using (var context = new ContextMaster()) { using (var transaction = context.Database.BeginTransaction()) { try { var count = context.Tenants.Count(t => t.Domain.ToLower() == tenant.Domain.ToLower()); if (count == 1) { throw (new Exception("The provided domain already exists in the system.")); } else if (count > 1) { throw (new Exception("The provided domain exists multiple times in the system.")); } tenant.DatabaseConnectionString = AzureDBConnectionStringBuilder(tenant.DatabaseConnectionString); tenantMasterTemp = context.Tenants.Add(tenant); context.SaveChanges(); tenantMasterTemp.MasterTenantId = tenantMasterTemp.Id; context.Entry(tenantMasterTemp).State = EntityState.Modified; context.SaveChanges(); if (tenantMasterTemp != null) { var tenantTenant = tenantMasterTemp.Clone(); tenantTenant.Id = 0; tenantTenant.MasterTenantId = tenant.Id; tenantTenant.TenantType = EntityMasterTenantType.Tenant; tenantTenant.AuthenticationType = AuthenticationType.None; ContextTenant.Initialize(tenantTenant.DatabaseConnectionString); // Commented out by Raheel to find a better way to automate the process. //using (var contexttenant = new ContextTenant (tenantTenant.DatabaseConnectionString)) //{ // bool seederresult = DataLayer.Seeders.SeederTenant.Seed (contexttenant, tenantTenant, out exception); // if (seederresult) // { // transaction.Commit (); // tenantMaster = tenantMasterTemp; // } // else // { // transaction.Rollback (); // } //} } } catch (Exception ex) { exception = ex; transaction.Rollback(); tenantMaster = tenant; } } } result = true; } catch (Exception e) { exception = e; tenantMaster = tenant; } return(result); }