Beispiel #1
0
        /// <summary>
        /// creates an organization for maphhive user and sets links as expected. org name, slug and such is based on user email!
        /// </summary>
        /// <param name="dbCtx"></param>
        /// <returns></returns>
        public async Task <Organization> CreateUserOrganizationAsync(DbContext dbCtx)
        {
            if (string.IsNullOrEmpty(Slug))
            {
                throw new Exception("Cannot create a user organization without a valid slug.");
            }

            //org creation step 1
            var org = new Organization
            {
                DisplayName = $"{Email}'s organization",
                Slug        = Utils.Slug.GetOrgSlug(null, Email) //no org name here
            };

            //tie up user to an org
            org.AddLink(this);

            await org.CreateAsync(dbCtx);


            //tie up the org to a user
            UserOrgId = org.Uuid;
            //add org owner role to user
            this.AddLink(await org.GetOrgOwnerRoleAsync(dbCtx));

            await this.UpdateAsync(dbCtx);

            return(org);
        }
Beispiel #2
0
        /// <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);
        }