Exemple #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);
        }
Exemple #2
0
        protected override void Execute(PluginContext context)
        {
            var integrationUserId = Guid.Parse(ConfigParameterHelper.GetValue(context.OrganizationService,
                                                                              ConfigParameterKeys.IntegrationUserId));

            if (context.PluginExecutionContext.UserId == integrationUserId)
            {
                return;
            }

            var preImage = context.GetPreImage <Contact>();

            if (preImage.CustomerType != Contact.CustomerTypeEnum.Individual)
            {
                return;
            }

            try
            {
                UpdateCustomerAsync(context).Wait();
            }
            catch (AggregateException e) when(e.InnerException is HttpRequestException)
            {
                throw new InvalidPluginExecutionException("Произошла ошибка при запросе MoVe API",
                                                          e.InnerException);
            }
        }
Exemple #3
0
        protected override void Execute(PluginContext context)
        {
            var integrationUserId = Guid.Parse(ConfigParameterHelper.GetValue(context.OrganizationService,
                                                                              ConfigParameterKeys.IntegrationUserId));

            if (context.PluginExecutionContext.UserId == integrationUserId)
            {
                return;
            }

            var target = context.GetTarget <Contact>();

            if (target.CustomerType != Contact.CustomerTypeEnum.Individual)
            {
                return;
            }

            if (context.Target.Attributes.ContainsKey(Contact.FieldNames.CustomerNumber) &&
                !string.IsNullOrEmpty(target.CustomerNumber))
            {
                return;
            }

            try
            {
                context.Target[Contact.FieldNames.CustomerNumber] = CreateCustomerAsync(context).Result;
            }
            catch (AggregateException e) when(e.InnerException is HttpRequestException)
            {
                throw new InvalidPluginExecutionException("Произошла ошибка при запросе MoVe API", e.InnerException);
            }
        }
Exemple #4
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));
        }
Exemple #5
0
        private bool ResolveMarkers(AccountKonturFocusModel accountData, Account proxy, IOrganizationService service, ITracingService tracingService)
        {
            tracingService.Trace("enter konturfocussynchronizationplugin.resolvemarkers");
            bool dissolved = false;

            if (accountData.UL != null && accountData.UL.status != null)
            {
                dissolved = accountData.UL.status.dissolved;
            }

            if (accountData.IP != null && accountData.IP.status != null)
            {
                dissolved = accountData.IP.status.dissolved;
            }

            if (dissolved)
            {
                proxy.OrganizationProblemTypeCode = OrganizationProblemTypeCodeEnum.Dissolved;
                tracingService.Trace("set organizationproblemtypecode dissolved");
                bool.TryParse(ConfigParameterHelper.GetValue(service, ConfigParameterKeys.Organization_Dissolve), out dissolved);
            }
            else
            {
                if (accountData.briefReport != null && accountData.briefReport.summary != null)
                {
                    if (accountData.briefReport.summary.greenStatements && !accountData.briefReport.summary.yellowStatements)
                    {
                        proxy.OrganizationProblemTypeCode = OrganizationProblemTypeCodeEnum.No;
                        tracingService.Trace("set organizationproblemtypecode no");
                    }

                    if (accountData.briefReport.summary.greenStatements && accountData.briefReport.summary.yellowStatements)
                    {
                        proxy.OrganizationProblemTypeCode = OrganizationProblemTypeCodeEnum.No;
                        tracingService.Trace("set organizationproblemtypecode no");
                    }

                    if ((accountData.briefReport.summary.yellowStatements && accountData.briefReport.summary.redStatements) ||
                        (accountData.briefReport.summary.redStatements))
                    {
                        proxy.OrganizationProblemTypeCode = OrganizationProblemTypeCodeEnum.HasProblem;
                        tracingService.Trace("set organizationproblemtypecode hasproblem");
                    }
                }
            }

            tracingService.Trace("exit konturfocussynchronizationplugin.resolvemarkers");
            return(dissolved);
        }