/// <summary> /// /// </summary> /// <param name="org"></param> /// <param name="dbCtx"></param> /// <param name="u"></param> /// <returns></returns> public static async Task AddOwnerAsync(this Organization org, DbContext dbCtx, MapHiveUser u) { //first find the owner role - it should always be there as it is created on org create var ownerR = await org.GetOrgOwnerRoleAsync(dbCtx); //and next link it to a user u.AddLink(ownerR); await u.UpdateWithNoIdentityChangesAsync <MapHiveUser>(dbCtx); //and also add a user to an org org.AddLink(u); await org.UpdateAsync(dbCtx); }
/// <summary> /// Creates and organisation account, register a user as an owner and registers the specified apps to be linked to it too /// </summary> /// <param name="org"></param> /// <param name="dbCtx"></param> /// <param name="owner"></param> /// <param name="appsToLink"></param> /// <returns></returns> public static async Task <Organization> CreateAsync(this Organization org, DbContext dbCtx, MapHiveUser owner, IEnumerable <Application> appsToLink) { //first create the org await org.CreateAsync(dbCtx); //take care of assigning the owner role to a user await org.AddOwnerAsync(dbCtx, owner); //finaly grab the apps that should be registered for the org and link them var mhDb = (MapHiveDbContext)dbCtx; foreach (var app in appsToLink) { org.AddLink(app); } await org.UpdateAsync(dbCtx, org.Uuid); return(org); }