using DigitalOps.Authority.Services; using DigitalOps.CQRS.Services.Organization.Options; using DigitalOps.Dal; using DigitalOps.Dal.DbEntity; namespace DigitalOps.CQRS.Services.Organization; public class OrganizationService(MainDbContext dbContext, UserIdentityService userIdentityService) { public async Task RegisterOrganizationAsync(RegisterOrganizationOptions options, CancellationToken cancellationToken = default) { var organization = new Dal.DbEntity.Organization { Name = options.Name }; var user = await userIdentityService.GetUserOrDefaultAsync(cancellationToken); if (null == user) return; var organizationUser = new OrganizationUser { Organization = organization, Role = OrganizationRole.Owner, UserId = user.Id, }; dbContext.OrganizationUsers.Add(organizationUser); await dbContext.SaveChangesAsync(cancellationToken); } }