Example #1
0
 private void JaExisteProduto(Domain.Model.ProdutoEstabelecimento produtoEstabelecimento)
 {
     if (ProEstabServ.VerificarExistenciaProduto(produtoEstabelecimento))
     {
         throw new ArgumentException("(CRM) O sistema não permite mais de um Produto do Estabelecimento.");
     }
 }
Example #2
0
        protected override void Execute(IPluginExecutionContext context, IOrganizationServiceFactory serviceFactory, IOrganizationService adminService, IOrganizationService userService)
        {
            var ServiceBeneficioDoCanal = new Intelbras.CRM2013.Domain.Servicos.BeneficioDoCanalService(context.OrganizationName, context.IsExecutingOffline);

            Domain.Model.ProdutoEstabelecimento prodEstabAtual = new Domain.Model.ProdutoEstabelecimento(context.OrganizationName, context.IsExecutingOffline);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                switch (Util.Utilitario.ConverterEnum <Domain.Enum.Plugin.MessageName>(context.MessageName))
                {
                case Domain.Enum.Plugin.MessageName.Create:
                    #region
                    var ent = (Entity)context.InputParameters["Target"];
                    Domain.Model.CategoriasCanal CatCanal = ent.Parse <Domain.Model.CategoriasCanal>(context.OrganizationName, context.IsExecutingOffline);

                    ServiceBeneficioDoCanal.VerificaDuplicidadeCategoria(CatCanal.Canal.Id, CatCanal.UnidadeNegocios.Id);

                    ServiceBeneficioDoCanal.VerificaConfiguracaoPerfilCategoria(CatCanal.Classificacao.Id, CatCanal.UnidadeNegocios.Id, CatCanal.Categoria.Id, CatCanal.Canal.Id);

                    // Insere o mesmo proprietário da Conta.
                    // Comentado devido problema com plugin do CRM2015 - não é possível alterar o OwnerId neste ponto - deixei comentado por enquanto
                    // var canalServices = new CategoriaCanalService(context.OrganizationName, context.IsExecutingOffline);
                    // ent = canalServices.AtribuiParaOProprietarioDoCanal(ent, CatCanal);

                    break;

                    #endregion
                case Domain.Enum.Plugin.MessageName.Update:
                    #region
                    if (context.PreEntityImages.Contains("imagem") && context.PreEntityImages["imagem"] is Entity)
                    {
                        var categoriasCanalPre = ((Entity)context.PreEntityImages["imagem"]).Parse <Domain.Model.CategoriasCanal>(context.OrganizationName, context.IsExecutingOffline);
                        var Entidade           = (Entity)context.InputParameters["Target"];

                        Domain.Model.CategoriasCanal categoriasCanal = Entidade.Parse <Domain.Model.CategoriasCanal>(context.OrganizationName, context.IsExecutingOffline);

                        if (categoriasCanal.UnidadeNegocios != null)
                        {
                            categoriasCanalPre.UnidadeNegocios = new SDKore.DomainModel.Lookup(categoriasCanal.UnidadeNegocios.Id, "");
                        }

                        if (categoriasCanal.Canal != null)
                        {
                            categoriasCanalPre.Canal = new SDKore.DomainModel.Lookup(categoriasCanal.Canal.Id, "");
                        }

                        if (categoriasCanal.Categoria != null)
                        {
                            categoriasCanalPre.Categoria = new SDKore.DomainModel.Lookup(categoriasCanal.Categoria.Id, "");
                        }

                        if (categoriasCanal.Classificacao != null)
                        {
                            categoriasCanalPre.Classificacao = new SDKore.DomainModel.Lookup(categoriasCanal.Classificacao.Id, "");
                        }

                        if (categoriasCanalPre.UnidadeNegocios != null &&
                            categoriasCanal.UnidadeNegocios != null &&
                            categoriasCanalPre.Canal != null &&
                            categoriasCanal.Canal != null)
                        {
                            if (categoriasCanalPre.UnidadeNegocios.Id != categoriasCanal.UnidadeNegocios.Id || categoriasCanalPre.Canal.Id != categoriasCanal.Canal.Id)
                            {
                                ServiceBeneficioDoCanal.VerificaDuplicidadeCategoria(categoriasCanalPre.Canal.Id, categoriasCanalPre.UnidadeNegocios.Id);
                            }
                        }

                        if (categoriasCanal.Canal == null)
                        {
                            categoriasCanal.Canal = categoriasCanalPre.Canal;
                        }

                        // Ativando Categoria do Canal
                        if (categoriasCanal.Status.HasValue &&
                            (categoriasCanalPre.Status == (int)Domain.Enum.CategoriaCanal.StateCode.Desativado &&
                             categoriasCanal.Status.Value == (int)Domain.Enum.CategoriaCanal.StateCode.Ativado))
                        {
                            ServiceBeneficioDoCanal.VerificaConfiguracaoPerfilCategoria(categoriasCanalPre.Classificacao.Id, categoriasCanalPre.UnidadeNegocios.Id, categoriasCanalPre.Categoria.Id, categoriasCanal.Canal.Id);
                        }
                    }

                    break;
                    #endregion
                }
            }
        }
Example #3
0
        public void Execute(IServiceProvider serviceProvider)
        {
            var             context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            ITracingService trace   = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(null);



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

                    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                    {
                        var entidade = (Entity)context.InputParameters["Target"];
                        Domain.Model.ProdutoEstabelecimento produtoEstabelecimento = entidade.Parse <Domain.Model.ProdutoEstabelecimento>(context.OrganizationName, context.IsExecutingOffline, service);
                        string lstResposta = new Domain.Servicos.ProdutoEstabelecimentoService(context.OrganizationName, context.IsExecutingOffline, service).IntegracaoBarramento(produtoEstabelecimento);
                    }

                    break;

                    #endregion

                    #region Update

                case Domain.Enum.Plugin.MessageName.Update:

                    if (context.PostEntityImages.Contains("imagem") && context.PostEntityImages["imagem"] is Entity)
                    {
                        var    prodEstabPost = ((Entity)context.PostEntityImages["imagem"]).Parse <Domain.Model.ProdutoEstabelecimento>(context.OrganizationName, context.IsExecutingOffline, service);
                        string lstResposta   = new Domain.Servicos.ProdutoEstabelecimentoService(context.OrganizationName, context.IsExecutingOffline, service).IntegracaoBarramento(prodEstabPost);
                    }

                    break;

                    #endregion

                    #region Delete

                case Domain.Enum.Plugin.MessageName.Delete:

                    if (context.PreEntityImages.Contains("imagem") && context.PreEntityImages["imagem"] is Entity)
                    {
                        var    prodEstabPost = ((Entity)context.PreEntityImages["imagem"]).Parse <Domain.Model.ProdutoEstabelecimento>(context.OrganizationName, context.IsExecutingOffline, service);
                        string lstResposta   = new Domain.Servicos.ProdutoEstabelecimentoService(context.OrganizationName, context.IsExecutingOffline, service).IntegracaoBarramentoDelete(prodEstabPost);
                    }
                    break;

                    #endregion
                }
            }
            catch (Exception ex)
            {
                trace.Trace(String.Format("EXCEPTION PLUGIN {0} {1} [{2}]", context.MessageName.ToLower(), "Account", DateTime.Now));
                trace.Trace(SDKore.Helper.Error.GetMessageError(ex));
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
Example #4
0
        public void Execute(IServiceProvider serviceProvider)
        {
            var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            ProEstabServ = new Domain.Servicos.ProdutoEstabelecimentoService(context.OrganizationName, context.IsExecutingOffline);

            try
            {
                Entity entidade = new Entity();
                Domain.Model.ProdutoEstabelecimento prodEstabAtual = new Domain.Model.ProdutoEstabelecimento(context.OrganizationName, context.IsExecutingOffline);

                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    switch (Util.Utilitario.ConverterEnum <Domain.Enum.Plugin.MessageName>(context.MessageName))
                    {
                    case Domain.Enum.Plugin.MessageName.Create:

                        #region Popula o objeto prodEstabAtual com o contexto

                        entidade       = (Entity)context.InputParameters["Target"];
                        prodEstabAtual = entidade.Parse <Domain.Model.ProdutoEstabelecimento>(context.OrganizationName, context.IsExecutingOffline);

                        #endregion

                        JaExisteProduto(prodEstabAtual);

                        break;

                    case Domain.Enum.Plugin.MessageName.Update:

                        if (context.PreEntityImages.Contains("imagem") && context.PreEntityImages["imagem"] is Entity)
                        {
                            #region Popula o objeto ProdEstabOriginal com a pre-image

                            entidade = (Entity)context.PreEntityImages["imagem"];
                            Domain.Model.ProdutoEstabelecimento ProdEstabOriginal = entidade.Parse <Domain.Model.ProdutoEstabelecimento>(context.OrganizationName, context.IsExecutingOffline);

                            #endregion

                            #region Popula objeto ProdEstabAlterado com o contexto alterado

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

                            #endregion

                            #region Popula objeto prodEstabAtual mesclando o que foi alterado com os dados originais, para efeito de validação

                            prodEstabAtual.Produto = ProdEstabAlterado.Produto != null ? ProdEstabAlterado.Produto : ProdEstabOriginal.Produto;

                            prodEstabAtual.ID = ProdEstabAlterado.ID != null ? ProdEstabAlterado.ID : ProdEstabOriginal.ID;


                            if (ProdEstabAlterado.Estabelecimento == null)
                            {
                                return;
                            }

                            if (prodEstabAtual.Estabelecimento == null)
                            {
                                if (ProdEstabOriginal.Estabelecimento.Id != ProdEstabAlterado.Estabelecimento.Id)
                                {
                                    return;
                                }
                            }

                            #endregion


                            if (prodEstabAtual.Estabelecimento.Id != ProdEstabAlterado.Estabelecimento.Id)
                            {
                                return;
                            }

                            JaExisteProduto(prodEstabAtual);
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                var msg = Util.Utilitario.TratarErro(ex);
                throw new InvalidPluginExecutionException(msg);
            }
        }
Example #5
0
 private bool ValidacoesFormulario(Domain.Model.ProdutoEstabelecimento produtoEstabelecimento)
 {
     return(true);
 }