/// <summary> /// Gets a list of admins of an organisation /// </summary> /// <param name="org"></param> /// <param name="dbCtx"></param> /// <returns></returns> public static async Task <IEnumerable <MapHiveUser> > GetAdminsAsync(this Organization org, DbContext dbCtx) { var mhDb = (MapHiveDbContext)dbCtx; var adminR = await org.GetOrgAdminRoleAsync(dbCtx); return(await adminR.GetParentsAsync <Role, MapHiveUser>(mhDb)); }
/// <summary> /// Removes owner from an organisation; this is done by simply removing a link to the admin role /// </summary> /// <param name="org"></param> /// <param name="dbCtx"></param> /// <param name="u"></param> /// <returns></returns> public static async Task RemoveAdminAsync(this Organization org, DbContext dbCtx, MapHiveUser u) { //first grab the admin role for the org var adminR = await org.GetOrgAdminRoleAsync(dbCtx); //and remove the link var mhDb = (MapHiveDbContext)dbCtx; mhDb.Links.Remove( mhDb.Links.FirstOrDefault(r => r.ParentUuid == u.Uuid && r.ChildUuid == adminR.Uuid)); await mhDb.SaveChangesAsync(); }
/// <summary> /// Adds a user to an org as an admin. /// </summary> /// <param name="org"></param> /// <param name="dbCtx"></param> /// <param name="u"></param> /// <returns></returns> public static async Task AddAdminAsync(this Organization org, DbContext dbCtx, MapHiveUser u) { //first find the admin role - it should always be there as it is created on org create var adminR = await org.GetOrgAdminRoleAsync(dbCtx); //and next link it to a user u.AddLink(adminR); await u.UpdateWithNoIdentityChangesAsync <MapHiveUser>(dbCtx); //and also add a user to an org - this will not change anything if a user is already linked org.AddLink(u); await org.UpdateAsync(dbCtx, org.Uuid); }