Beispiel #1
0
        protected override void Execute(IPluginExecutionContext context, IOrganizationServiceFactory serviceFactory, IOrganizationService adminService, IOrganizationService userService)
        {
            var historicoDistService = new Domain.Servicos.HistoricoDistribuidorService(context.OrganizationName, context.IsExecutingOffline, adminService);

            switch (Util.Utilitario.ConverterEnum <Domain.Enum.Plugin.MessageName>(context.MessageName))
            {
            case Domain.Enum.Plugin.MessageName.Create:
                var entityTargetCreate = context.GetContextEntity();
                var histDistCreate     = entityTargetCreate.Parse <Domain.Model.HistoricoDistribuidor>(context.OrganizationName, context.IsExecutingOffline, adminService);

                histDistCreate.Status = (int)Domain.Enum.HistoricoDistribuidor.Statecode.Ativo;
                var historicDistService = new Domain.Servicos.HistoricoDistribuidorService(context.OrganizationName, context.IsExecutingOffline, adminService);
                if (!histDistCreate.IntegrarNoPlugin || histDistCreate.IntegrarNoPlugin == null || histDistCreate.IntegrarNoPlugin.ToString().Equals(""))
                {
                    historicoDistService.Integrar(histDistCreate);
                }

                break;

            case Domain.Enum.Plugin.MessageName.Update:

                Entity entidadeAlterada = (Entity)context.InputParameters["Target"];
                Domain.Model.HistoricoDistribuidor historicoDistribuidor = entidadeAlterada.Parse <Domain.Model.HistoricoDistribuidor>(context.OrganizationName, context.IsExecutingOffline);

                var entityMergeUpdate = context.GetContextEntity("postimagem");
                var histDistUpdate    = entityMergeUpdate.Parse <Domain.Model.HistoricoDistribuidor>(context.OrganizationName, context.IsExecutingOffline, adminService);

                histDistUpdate.IntegrarNoPlugin = historicoDistribuidor.IntegrarNoPlugin;

                if (!histDistUpdate.IntegrarNoPlugin || histDistUpdate.IntegrarNoPlugin == null || histDistUpdate.IntegrarNoPlugin.ToString().Equals(""))
                {
                    historicoDistService.Integrar(histDistUpdate);
                }

                break;

            case Domain.Enum.Plugin.MessageName.SetStateDynamicEntity:
                if (context.PostEntityImages.Contains("imagem") && context.PostEntityImages["imagem"] is Entity)
                {
                    var histDistServiceState = new Domain.Servicos.HistoricoDistribuidorService(context.OrganizationName, context.IsExecutingOffline, adminService);
                    var histDist             = ((Entity)context.PostEntityImages["imagem"]).Parse <Domain.Model.HistoricoDistribuidor>(context.OrganizationName, context.IsExecutingOffline, adminService);

                    var crmAdmin = SDKore.Configuration.ConfigurationManager.GetSettingValue("ID_CRMADMIN");

                    if (histDist.ModificadoPor.Id != new Guid(crmAdmin))
                    {
                        histDistServiceState.Integrar(histDist);
                    }
                }

                break;
            }
        }
Beispiel #2
0
        protected override void Execute(IPluginExecutionContext context, IOrganizationServiceFactory serviceFactory, IOrganizationService adminService, IOrganizationService userService)
        {
            var historicoDistribuidorService = new Domain.Servicos.HistoricoDistribuidorService(context.OrganizationName, context.IsExecutingOffline, adminService);

            switch (Util.Utilitario.ConverterEnum <Domain.Enum.Plugin.MessageName>(context.MessageName))
            {
            case Domain.Enum.Plugin.MessageName.Create:

                var entityTargetCreate = context.GetContextEntity();
                var targetCreate       = entityTargetCreate.Parse <Domain.Model.HistoricoDistribuidor>(context.OrganizationName, context.IsExecutingOffline, adminService);
                targetCreate.Status = (int)Domain.Enum.HistoricoDistribuidor.Statecode.Ativo;
                historicoDistribuidorService.ValidaCamposObrigatorios(targetCreate);
                historicoDistribuidorService.ValidaDuplicidade(targetCreate, true);

                var revenda      = new Domain.Servicos.ContaService(context.OrganizationName, context.IsExecutingOffline, userService).BuscaConta(targetCreate.Revenda.Id);
                var distribuidor = new Domain.Servicos.ContaService(context.OrganizationName, context.IsExecutingOffline, userService).BuscaConta(targetCreate.Distribuidor.Id);

                PreencheNome(ref entityTargetCreate, ref revenda, ref distribuidor);

                break;

            case Domain.Enum.Plugin.MessageName.Update:

                var entityTargetMerge  = context.GetContextEntityMerge("imagem");
                var entityTargetUpdate = context.GetContextEntity();
                var targetUpdate       = entityTargetMerge.Parse <Domain.Model.HistoricoDistribuidor>(context.OrganizationName, context.IsExecutingOffline, adminService);
                var entityTarget       = (Entity)context.InputParameters["Target"];
                var contaUp            = entityTarget.Parse <Domain.Model.HistoricoDistribuidor>(context.OrganizationName, context.IsExecutingOffline, adminService);

                entityTargetUpdate.Attributes["itbc_datafim"] = contaUp.DataFim;

                if (targetUpdate.Status.Value == (int)Domain.Enum.HistoricoDistribuidor.Statecode.Ativo)
                {
                    historicoDistribuidorService.ValidaCamposObrigatorios(targetUpdate);
                    historicoDistribuidorService.ValidaDuplicidade(targetUpdate, false);
                }

                var revendaUpdate      = new Domain.Servicos.ContaService(context.OrganizationName, context.IsExecutingOffline, userService).BuscaConta(targetUpdate.Revenda.Id);
                var distribuidorUpdate = new Domain.Servicos.ContaService(context.OrganizationName, context.IsExecutingOffline, userService).BuscaConta(targetUpdate.Distribuidor.Id);

                PreencheNome(ref entityTargetUpdate, ref revendaUpdate, ref distribuidorUpdate);
                break;
            }
        }