public async Task TestCreateReadUpdateDeleteContactPerson(long customerId)
        {
            var newContactPerson = new NewContactPerson
            {
                FirstName = "Created by an automated test",
                LastName  = "(Should have been deleted)"
            };

            var createdContactPerson = await Client.CreateContactPerson(customerId, newContactPerson);

            createdContactPerson.FirstName.Should().Be(newContactPerson.FirstName);
            createdContactPerson.LastName.Should().Be(newContactPerson.LastName);

            var readContactPerson = await Client.GetContactPerson(customerId, createdContactPerson.Id);

            readContactPerson.Id.Should().Be(createdContactPerson.Id);
            readContactPerson.FirstName.Should().Be(createdContactPerson.FirstName);
            readContactPerson.LastName.Should().Be(createdContactPerson.LastName);

            createdContactPerson.FirstName = "Created and updated by an automated test";
            var updatedContactPerson = await Client.UpdateContactPerson(customerId, createdContactPerson);

            updatedContactPerson.Id.Should().Be(createdContactPerson.Id);
            updatedContactPerson.FirstName.Should().Be(createdContactPerson.FirstName);
            updatedContactPerson.LastName.Should().Be(createdContactPerson.LastName);

            await Client.DeleteContactPerson(customerId, updatedContactPerson.Id);

            var deletedContactPerson = await Client.GetContactPerson(customerId, updatedContactPerson.Id);

            deletedContactPerson.Should().BeNull();
        }
Exemplo n.º 2
0
        public async Task <ContactPerson> CreateContactPerson(long customerId, NewContactPerson newContactPerson)
        {
            var createResponse = await AuthorizedPost($"Customer/{customerId}/Contact", newContactPerson);

            var createdContactPerson = await DeserializeScalarResponse <ContactPerson>(createResponse, "contact person");

            return(createdContactPerson);
        }
Exemplo n.º 3
0
        public async Task CopyPersonToPoweroffice(
            PersonDto webcrmPerson)
        {
            var personKey = webcrmPerson.GetPowerofficePersonKey(Logger, Configuration.PersonIdFieldName);

            if (personKey == null)
            {
                long?powerofficeOrganisationId = await GetPowerofficeOrganisationId(webcrmPerson);

                if (powerofficeOrganisationId == null)
                {
                    throw new ApplicationException("Cannot create person in PowerOffice without an associated organisation.");
                }

                Logger.LogTrace("Copying person to PowerOffice, creating a new one.");
                var newPowerofficePerson = new NewContactPerson();
                newPowerofficePerson.Update(webcrmPerson);
                var createdPowerofficePerson = await PowerofficeClient.CreateContactPerson(powerofficeOrganisationId.Value, newPowerofficePerson);

                personKey = new PowerofficePersonKey(powerofficeOrganisationId.Value, createdPowerofficePerson.Id);
                webcrmPerson.SetPowerofficePersonKey(Configuration.PersonIdFieldName, personKey);
                await WebcrmClient.UpdatePerson(webcrmPerson);
            }
            else
            {
                var matchingPowerofficePerson = await PowerofficeClient.GetContactPerson(personKey.PowerofficeOrganisationId, personKey.PowerofficePersonId);

                if (matchingPowerofficePerson == null)
                {
                    Logger.LogWarning($"Could not find PowerOffice person (contact person) with key {personKey}.");
                    return;
                }

                if (!matchingPowerofficePerson.HasRelevantChanges(webcrmPerson))
                {
                    Logger.LogTrace("Not copying person to PowerOffice because it does not have any relevant changes.");
                    return;
                }

                Logger.LogTrace("Copying person to PowerOffice, updating an existing one.");
                matchingPowerofficePerson.Update(webcrmPerson);
                await PowerofficeClient.UpdateContactPerson(personKey.PowerofficeOrganisationId, matchingPowerofficePerson);
            }
        }