Exemplo n.º 1
0
        public async Task CreateAsync(CreateOrganisationRequest payload)
        {
            var companyNameRef = payload.FormResponse.Definition.Fields
                                 .FirstOrDefault(t => string.Equals(t.Title, DefinitionConstants.CompanyName, StringComparison.Ordinal))?
                                 .Reference;

            var companyName = payload.FormResponse.Answers
                              .FirstOrDefault(t => string.Equals(t.Field.Reference, companyNameRef, StringComparison.Ordinal))?
                              .Text;

            var organisation = new Organisation()
            {
                Name      = companyName,
                Payload   = JsonConvert.SerializeObject(payload),
                CreatedAt = DateTime.UtcNow
            };

            await _organisationRepository.AddAsync(organisation);

            await _organisationRepository.SaveAsync();

            await NotifyOrganisation(companyName, payload, organisation);
        }
Exemplo n.º 2
0
        public async Task <Organisation> RegisterAsync(OrganisationRegistration organisationContract)
        {
            if (await repository.ExistsByAsync(o => o.Id == organisationContract.Id))
            {
                throw new NameAlreadyUsedException(organisationContract.Name);
            }
            var organisationEntity = organisationContract.ToEntity();

            organisationEntity = await repository.AddAsync(organisationEntity);


            var user = GeneratePasswordAndAttachAdminRole(organisationContract.AdminUser, organisationContract.Id);

            user.CreatedAt = DateTime.Now;
            user           = await userRepository.AddAsync(user);

            var administrationTeam = new Domain.Entities.Team
            {
                Name           = "org-admin",
                TeamCode       = "org-admin",
                OrganisationId = organisationContract.Id,
                CreatedAt      = DateTime.Now
            };

            administrationTeam.Users.Add(new Domain.Entities.TeamUser(user));

            administrationTeam = await teamRepository.AddAsync(administrationTeam);

            user.TeamsPermissions.Add(new Domain.Entities.TeamPermission
            {
                TeamCode = administrationTeam.TeamCode,
                IsOwner  = true
            });
            user = await userRepository.UpdateAsync(user);

            return(organisationEntity.ToContract());
        }