Esempio n. 1
0
        public async Task PushOrganizationToEPaadAsync(OrganizationDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            if (dto.OrganizationTypeId == campOrganizationTypeId)
            {
                ValidationDictionary
                .AddModelError("Camps can not be pushed to Epaad", $"Camps can not be pushed to Epaad.");
                return;
            }

            var existinOrganizationType = await _organizationTypesRepository
                                          .AnyOrganizationTypeAsync(x => x.Id == dto.OrganizationTypeId)
                                          .ConfigureAwait(false);

            if (!existinOrganizationType)
            {
                ValidationDictionary
                .AddModelError("Organization type not found", $"Organization type with that id doesn't exist.");

                return;
            }

            var city = await _citiesRepository
                       .GetCityEpaadDtoAsync(dto.CityId)
                       .ConfigureAwait(false);

            var organizationCreationDate = await _organizationsRepository
                                           .GetOrganizationCreationDateAsync(dto.Id)
                                           .ConfigureAwait(false);

            var epaadOrgDto = new PushEpaadOrganizationDto
            {
                ContactPersonEmail = dto.Contacts.First().Email,
                ContactPersonName  = dto.Contacts.First().Name,
                ContactPersonPhone = dto.Contacts.First().PhoneNumber,
                OrganizationTypeId = dto.OrganizationTypeId == smeOrganizationTypeId ? companyOrganizationTypeId : dto.OrganizationTypeId,
                OrganizationName   = dto.Name,
                City             = city.Name,
                CountryShortName = city.CountryShortName,
                Zip           = dto.Zip ?? city.ZipCode,
                FilterText    = dto.OrganizationShortcutName,
                State         = DefaultEpaadOrganizationState,
                ActiveSince   = organizationCreationDate,
                Address       = dto.Address,
                PoolLastname  = dto.Name,
                PoolFirstName = dto.OrganizationTypeId == smeOrganizationTypeId ? smeOrgTypePoolFirstName : default
            };

            var response = await _epaadService
                           .PushOrganizationToEpaadAsync(epaadOrgDto)
                           .ConfigureAwait(false);

            if (response == null || !response.EpaadId.HasValue)
            {
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
                throw new ArgumentNullException(paramName: "Epaad response");
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
            }

            await _organizationsRepository
            .UpdateEpaadIdAsync(response.EpaadId.Value, dto.Id)
            .ConfigureAwait(false);
        }