Beispiel #1
0
        public async Task <int> CreateOrganizationAsync(Party signingAuthority)
        {
            if (signingAuthority == null)
            {
                throw new ArgumentNullException(nameof(signingAuthority), "Could not create a site, the passed in Party cannot be null.");
            }

            var partyExists = await _partyService.PartyExistsAsync(signingAuthority.Id);

            var signingAuthorityId = signingAuthority.Id;

            if (!partyExists)
            {
                signingAuthorityId = await _partyService.CreatePartyAsync(signingAuthority);
            }

            var organization = new Organization
            {
                SigningAuthorityId = signingAuthorityId
            };

            _context.Organizations.Add(organization);

            var created = await _context.SaveChangesAsync();

            if (created < 1)
            {
                throw new InvalidOperationException("Could not create Organization.");
            }

            await _businessEventService.CreateOrganizationEventAsync(organization.Id, signingAuthorityId, "Organization Created");

            return(organization.Id);
        }
        public async Task <int> CreateOrganizationAsync(Party signingAuthority)
        {
            signingAuthority.ThrowIfNull(nameof(signingAuthority));

            var userId = _httpContext.HttpContext.User.GetPrimeUserId();

            var partyExists = await _partyService.PartyUserIdExistsAsync(userId);

            if (!partyExists)
            {
                await _partyService.CreatePartyAsync(signingAuthority);
            }

            signingAuthority = await _partyService.GetPartyForUserIdAsync(userId);

            var organizations = await GetOrganizationsAsync(signingAuthority.Id);

            if (organizations.Count() != 0)
            {
                throw new InvalidOperationException("Could not create Organization. Only one organization can exist for a party.");
            }

            var organization = new Organization
            {
                SigningAuthorityId = signingAuthority.Id
            };

            _context.Organizations.Add(organization);

            var created = await _context.SaveChangesAsync();

            if (created < 1)
            {
                throw new InvalidOperationException("Could not create Organization.");
            }

            await _businessEventService.CreateOrganizationEventAsync(organization.Id, signingAuthority.Id, "Organization Created");

            return(organization.Id);
        }