Exemplo n.º 1
0
        private async Task UpdateCustomerAsync(PluginContext pluginContext)
        {
            var config = ConfigParameterHelper.GetValues(pluginContext.OrganizationService,
                                                         ConfigParameterKeys.MoveAutorizationUrl, ConfigParameterKeys.MoveRequestUrl,
                                                         ConfigParameterKeys.MoveClientId, ConfigParameterKeys.MoveClientSecret);
            var moveApi = new MoveApi(pluginContext.OrganizationService, config[ConfigParameterKeys.MoveRequestUrl], config[ConfigParameterKeys.MoveAutorizationUrl],
                                      config[ConfigParameterKeys.MoveClientId], config[ConfigParameterKeys.MoveClientSecret]);

            var target         = pluginContext.GetTarget <Contact>();
            var preImage       = pluginContext.GetPreImage <Contact>();
            var customerNumber = preImage.CustomerNumber;

            var fullCustomerJson = await moveApi.GetCustomerAsync(customerNumber);

            var initialCustomer = GetInitialCustomer(fullCustomerJson);

            var mapper          = new MoveApiMapper(pluginContext.OrganizationService);
            var updatedCustomer = mapper.Map(target, initialCustomer);

            await DeleteAddresses(moveApi, initialCustomer, updatedCustomer);
            await DeleteCommunicationOptions(moveApi, initialCustomer, updatedCustomer);

            var data = MergeData(fullCustomerJson, updatedCustomer);

            //pluginContext.TracingService.Trace(target.PassportIssueDate?.ToString("F"));
            pluginContext.TracingService.Trace(data);
            await moveApi.UpdateCustomerAsync(customerNumber, data);
        }
Exemplo n.º 2
0
        private async Task <string> CreateCustomerAsync(PluginContext context)
        {
            var mapper   = new MoveApiMapper(context.OrganizationService);
            var customer = mapper.Map(context.GetTarget <Contact>());

            customer = mapper.FillDefaults(customer);
            var config = ConfigParameterHelper.GetValues(context.OrganizationService,
                                                         ConfigParameterKeys.MoveAutorizationUrl, ConfigParameterKeys.MoveRequestUrl,
                                                         ConfigParameterKeys.MoveClientId, ConfigParameterKeys.MoveClientSecret);
            var moveApi = new MoveApi(context.OrganizationService, config[ConfigParameterKeys.MoveRequestUrl], config[ConfigParameterKeys.MoveAutorizationUrl],
                                      config[ConfigParameterKeys.MoveClientId], config[ConfigParameterKeys.MoveClientSecret]);

            return(await moveApi.CreateCustomerAsync(customer));
        }