public void Configure(CommandLineApplication command) { command.Description = "deletes a tenant (optionally with its databases and found backups)"; var tenantNamesArg = command.Argument("tenant", "the tenant(s) id", true); var hardOption = command.Option("--hard", "deletes the related databases and webapps (use with caution)", CommandOptionType.NoValue); command.OnExecute(() => { foreach (var tenantName in tenantNamesArg.Values) { var tenant = _t(_db.Find <Tenant>(tenantName)); var server = _db.Find <Server>(tenant.Dto.ServerId); if (hardOption.HasValue()) { tenant.DropAdminWebApp(); tenant.DropPublicWebApp(); server.DropDatabase(tenant.Dto.ConfigDb); server.DropDatabase(tenant.Dto.PublicDb); } _db.Tenants.Remove(tenant.Dto); _db.SaveChanges(); } return(0); }); }
public static void Upsert <T, TKey>(this PlsDbContext db, T newItem, Expression <Func <T, TKey> > on) where T : class { if (newItem == null) { throw new ArgumentNullException(nameof(newItem)); } if (@on == null) { throw new ArgumentNullException(nameof(@on)); } var id = on.Compile()(newItem); T item; if ((item = db.Find <T>(id)) != null) { item.InjectFrom(newItem); } else { db.Add(newItem); } }