Ejemplo n.º 1
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="data">The data.</param>
        public override void SetValue(string value, params string[] data)
        {
            if (this.Adaptee is StateProperty)
            {
                ((StateProperty)this.Adaptee).Value = value;
                return;
            }

            if (this.Adaptee is StringProperty)
            {
                ((StringProperty)this.Adaptee).Value = value;
                return;
            }

            if (this.Adaptee is UniqueIdentifierProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var identifier = new UniqueIdentifier {
                        Value = idValue.Guid
                    };
                    ((UniqueIdentifierProperty)this.Adaptee).Value = identifier;
                }

                return;
            }

            if (this.Adaptee is StatusProperty)
            {
                int intValue;
                if (int.TryParse(value, out intValue))
                {
                    var status = new Status {
                        Value = intValue
                    };
                    ((StatusProperty)this.Adaptee).Value = status;
                }

                return;
            }

            if (this.Adaptee is PicklistProperty)
            {
                string   picklistValue = value;
                Picklist list          = null;
                int      intValue;

                if (!string.IsNullOrEmpty(picklistValue) && int.TryParse(picklistValue, out intValue))
                {
                    list = new Picklist {
                        Value = intValue
                    };
                }
                else
                {
                    picklistValue = null;
                }

                if (string.IsNullOrEmpty(picklistValue))
                {
                    list = new Picklist
                    {
                        IsNull          = true,
                        IsNullSpecified = true
                    };
                }

                ((PicklistProperty)this.Adaptee).Value = list;
                return;
            }

            if (this.Adaptee is OwnerProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var owner = new Owner {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((OwnerProperty)this.Adaptee).Value = owner;
                }

                return;
            }

            if (this.Adaptee is LookupProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var lookup = new Lookup {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((LookupProperty)this.Adaptee).Value = lookup;
                }

                return;
            }

            if (this.Adaptee is KeyProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var key = new Key {
                        Value = idValue.Guid
                    };
                    ((KeyProperty)this.Adaptee).Value = key;
                }

                return;
            }

            if (this.Adaptee is EntityNameReferenceProperty)
            {
                var reference = new EntityNameReference {
                    Value = value
                };
                ((EntityNameReferenceProperty)this.Adaptee).Value = reference;
                return;
            }

            if (this.Adaptee is DynamicEntityArrayProperty)
            {
                var dynamycProperty = (DynamicEntityArrayProperty)this.Adaptee;

                dynamycProperty.Value = new[]
                {
                    new DynamicEntity
                    {
                        Name       = "activityparty",
                        Properties = new[]
                        {
                            new LookupProperty
                            {
                                Name  = "partyid",
                                Value = new Lookup
                                {
                                    Value = new Guid(value),
                                    type  = data[0]
                                }
                            }
                        }
                    }
                };
            }

            if (this.Adaptee is CustomerProperty)
            {
                ID idValue;
                if (ID.TryParse(value, out idValue))
                {
                    var customer = new Customer {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((CustomerProperty)this.Adaptee).Value = customer;
                }

                return;
            }

            if (this.Adaptee is CrmNumberProperty)
            {
                int intValue;
                if (int.TryParse(value, out intValue))
                {
                    var number = new CrmNumber {
                        Value = intValue
                    };
                    ((CrmNumberProperty)this.Adaptee).Value = number;
                }

                return;
            }

            if (this.Adaptee is CrmMoneyProperty)
            {
                decimal decimalValue;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var money = new CrmMoney {
                        Value = decimalValue
                    };
                    ((CrmMoneyProperty)this.Adaptee).Value = money;
                }

                return;
            }

            if (this.Adaptee is CrmFloatProperty)
            {
                float decimalValue;
                if (float.TryParse(value, out decimalValue))
                {
                    var crmFloat = new CrmFloat {
                        Value = decimalValue
                    };
                    ((CrmFloatProperty)this.Adaptee).Value = crmFloat;
                }

                return;
            }

            if (this.Adaptee is CrmDecimalProperty)
            {
                decimal decimalValue;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var crmDecimal = new CrmDecimal {
                        Value = decimalValue
                    };
                    ((CrmDecimalProperty)this.Adaptee).Value = crmDecimal;
                }

                return;
            }

            if (this.Adaptee is CrmDateTimeProperty)
            {
                DateTime parsedValue;
                if (value.TryParseDateTime(out parsedValue))
                {
                    ((CrmDateTimeProperty)this.Adaptee).Value = new CrmDateTime {
                        Value = parsedValue.ToCrmDateTimeString()
                    };
                }
            }

            if (this.Adaptee is CrmBooleanProperty)
            {
                var boolValue = MainUtil.GetBool(value, false);
                var crmBool   = new CrmBoolean {
                    Value = boolValue
                };
                ((CrmBooleanProperty)this.Adaptee).Value = crmBool;
            }
        }
Ejemplo n.º 2
0
 public static decimal?Convert(CrmMoney obj)
 {
     return(obj.IsNull == false ? (decimal?)obj.Value : null);
 }
        public virtual void SetPropertyValue(Property property, string value, params string[] data)
        {
            Assert.ArgumentNotNull(property, "property");

            if (property is StateProperty)
            {
                ((StateProperty)property).Value = value;
                return;
            }

            if (property is StringProperty)
            {
                ((StringProperty)property).Value = value;
                return;
            }

            if (property is UniqueIdentifierProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var identifier = new UniqueIdentifier {
                        Value = idValue.Guid
                    };
                    ((UniqueIdentifierProperty)property).Value = identifier;
                }
                return;
            }

            if (property is StatusProperty)
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    var status = new Status {
                        Value = intValue
                    };
                    ((StatusProperty)property).Value = status;
                }

                return;
            }

            if (property is PicklistProperty)
            {
                string   picklistValue = value;
                Picklist list          = null;
                int      intValue      = 0;

                if (!string.IsNullOrEmpty(picklistValue) && int.TryParse(picklistValue, out intValue))
                {
                    list = new Picklist {
                        Value = intValue
                    };
                }
                else
                {
                    picklistValue = null;
                }

                if (string.IsNullOrEmpty(picklistValue))
                {
                    list = new Picklist
                    {
                        IsNull          = true,
                        IsNullSpecified = true
                    };
                }

                ((PicklistProperty)property).Value = list;
                return;
            }

            if (property is OwnerProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var owner = new Owner {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((OwnerProperty)property).Value = owner;
                }
                return;
            }

            if (property is LookupProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var lookup = new Lookup {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((LookupProperty)property).Value = lookup;
                }
                return;
            }

            if (property is KeyProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var key = new CrmCampaignIntegration.Services.Key {
                        Value = idValue.Guid
                    };
                    ((KeyProperty)property).Value = key;
                }
                return;
            }

            if (property is EntityNameReferenceProperty)
            {
                var reference = new EntityNameReference {
                    Value = value
                };
                ((EntityNameReferenceProperty)property).Value = reference;
                return;
            }

            if (property is DynamicEntityArrayProperty)
            {
                var dynamycProperty = (DynamicEntityArrayProperty)property;

                dynamycProperty.Value = new[]
                {
                    new DynamicEntity {
                        Name       = "activityparty",
                        Properties = new []
                        {
                            new LookupProperty
                            {
                                Name  = "partyid",
                                Value = new Lookup
                                {
                                    Value = new Guid(value),
                                    type  = data[0]
                                }
                            }
                        }
                    }
                };
            }

            if (property is CustomerProperty)
            {
                ID idValue = null;
                if (ID.TryParse(value, out idValue))
                {
                    var customer = new Customer {
                        Value = idValue.Guid, type = data[0]
                    };
                    ((CustomerProperty)property).Value = customer;
                }
                return;
            }

            if (property is CrmNumberProperty)
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    var number = new CrmCampaignIntegration.Services.CrmNumber {
                        Value = intValue
                    };
                    ((CrmNumberProperty)property).Value = number;
                }
                return;
            }

            if (property is CrmMoneyProperty)
            {
                decimal decimalValue = 0;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var money = new CrmMoney {
                        Value = decimalValue
                    };
                    ((CrmMoneyProperty)property).Value = money;
                }
                return;
            }

            if (property is CrmFloatProperty)
            {
                float decimalValue = 0;
                if (float.TryParse(value, out decimalValue))
                {
                    var crmFloat = new CrmCampaignIntegration.Services.CrmFloat {
                        Value = decimalValue
                    };
                    ((CrmFloatProperty)property).Value = crmFloat;
                }
                return;
            }

            if (property is CrmDecimalProperty)
            {
                decimal decimalValue = 0;
                if (decimal.TryParse(value, out decimalValue))
                {
                    var crmDecimal = new CrmDecimal {
                        Value = decimalValue
                    };
                    ((CrmDecimalProperty)property).Value = crmDecimal;
                }
                return;
            }

            if (property is CrmDateTimeProperty)
            {
                var dateTime = Sitecore.CrmCampaignIntegrations.Core.Utility.DateUtil.ToCrmDateTime(value);
                if (dateTime != null)
                {
                    var crmDateTime = new CrmCampaignIntegration.Services.CrmDateTime {
                        Value = dateTime.Value
                    };
                    ((CrmDateTimeProperty)property).Value = crmDateTime;
                }
            }

            if (property is CrmBooleanProperty)
            {
                var boolValue = MainUtil.GetBool(value, false);
                var crmBool   = new CrmCampaignIntegration.Services.CrmBoolean {
                    Value = boolValue
                };
                ((CrmBooleanProperty)property).Value = crmBool;
                return;
            }
        }
        public HttpResponseMessage Get(string id)
        {
            string XML = "";

            Integration1C_log.Info($"Integration1C. Get id='{id}'");
            //595CC35C-30D2-E911-80CC-005056BAC107
            BusinessEntityCollection opportunity;
            Opp        o                     = new Opp();
            string     nameopp               = "";               //номер договора
            Lookup     new_contact2id        = new Lookup();     //Законный представитель ФЛ/ Подписант ЮЛ
            CrmBoolean new_pay_installments  = new CrmBoolean(); //рассрочка в банке
            CrmFloat   new_discountpercent   = new CrmFloat();   //% комиссии банка
            CrmMoney   new_commission_amount = new CrmMoney();   //Сумма комиссии банка
            CrmMoney   new_totalsumcost      = new CrmMoney();   //Общая стоимость обучения с учетом пособий

            try
            {
                opportunity = o.searchOpportunity(id);
                foreach (DynamicEntity opp in opportunity.BusinessEntities)
                {
                    nameopp = opp["name"].ToString();

                    if (opp.Properties.Contains("new_contact2id"))
                    {
                        new_contact2id = (Lookup)opp["new_contact2id"];
                    }

                    if (opp.Properties.Contains("new_pay_installments"))
                    {
                        new_pay_installments = (CrmBoolean)opp["new_pay_installments"];
                    }

                    if (opp.Properties.Contains("new_discountpercent"))
                    {
                        new_discountpercent = (CrmFloat)opp["new_discountpercent"];
                    }

                    if (opp.Properties.Contains("new_commission_amount"))
                    {
                        new_commission_amount = (CrmMoney)opp["new_commission_amount"];
                    }

                    if (opp.Properties.Contains("new_totalsumcost"))
                    {
                        new_totalsumcost = (CrmMoney)opp["new_totalsumcost"];
                    }
                }


                XML = String.Format("<report><opportunityid>{0}</opportunityid><name>{1}</name><new_contact2id>{2}</new_contact2id><new_pay_installments>{3}</new_pay_installments><new_discountpercent>{4}</new_discountpercent><new_commission_amount>{5}</new_commission_amount><new_totalsumcost>{6}</new_totalsumcost></report>", id, nameopp, new_contact2id.Value.ToString(), new_pay_installments.Value, new_discountpercent.Value, new_commission_amount.Value, new_totalsumcost.Value);
                Integration1C_log.Info($"Integration1C. Response xml='{XML}'");
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(XML, Encoding.UTF8, "application/xml")
                });
            }
            catch (Exception ex)
            {
                XML = String.Format("<report><error>{0}</error></report>", ex.ToString());

                return(new HttpResponseMessage()
                {
                    Content = new StringContent(XML, Encoding.UTF8, "application/xml")
                });
            }
        }
Ejemplo n.º 5
0
        public void Execute(IPluginExecutionContext context)
        {
            DateTime inicioExecucao = DateTime.Now;

            try
            {
                var prop = context.InputParameters.Properties;
                if (prop.Contains("Target") && prop["Target"] is DynamicEntity)
                {
                    PluginHelper.LogEmArquivo(context, "INICIO;", inicioExecucao.ToString(), "");
                    var organizacao = new Organizacao(context.OrganizationName);
                    var entidade    = prop["Target"] as DynamicEntity;

                    FacadeOcorrencia facade = new FacadeOcorrencia(context);
                    facade.Atender();

                    #region inserir resultado do atendimento do contexto

                    #region reincidencia

                    if (facade.Ocorrencia.OcorrenciaPai != null)
                    {
                        if (facade.Ocorrencia.OcorrenciaPai.Id != Guid.Empty)
                        {
                            entidade = PluginHelper.AdicionarPropriedadeEmEntidadeDinamica(entidade, "new_reincidenteid", new Lookup("incident", facade.Ocorrencia.OcorrenciaPai.Id));
                        }

                        if (facade.Ocorrencia.OcorrenciaPai.DataDeCriacao != DateTime.MinValue)
                        {
                            context.SharedVariables.Properties.Add(
                                new PropertyBagEntry("dataCriacaoReincidente", facade.Ocorrencia.OcorrenciaPai.DataDeCriacao.ToString())
                                );
                        }
                    }

                    #endregion

                    #region SLA

                    var sla = new CrmDateTime()
                    {
                        IsNull = true, IsNullSpecified = true
                    };
                    if (facade.Ocorrencia.DataSLA.HasValue)
                    {
                        sla = new CrmDateTime(facade.Ocorrencia.DataSLA.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                    }
                    entidade = PluginHelper.AdicionarPropriedadeEmEntidadeDinamica(entidade, "followupby", sla);

                    var escalacao = new CrmDateTime()
                    {
                        IsNull = true, IsNullSpecified = true
                    };
                    if (facade.Ocorrencia.DataEscalacao.HasValue)
                    {
                        escalacao = new CrmDateTime(facade.Ocorrencia.DataEscalacao.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                    }
                    entidade = PluginHelper.AdicionarPropriedadeEmEntidadeDinamica(entidade, "new_data_hora_escalacao", escalacao);

                    #endregion

                    #region  árvore de assunto

                    if (facade.Ocorrencia.EstruturaDeAssunto != null)
                    {
                        foreach (Assunto item in facade.Ocorrencia.EstruturaDeAssunto)
                        {
                            if (item.TipoDeAssunto != TipoDeAssunto.Vazio)
                            {
                                entidade = PluginHelper.AdicionarPropriedadeEmEntidadeDinamica(entidade, item.CampoRelacionadoNaOcorrencia, new Lookup("subject", item.Id));
                            }
                        }
                    }

                    #endregion

                    #region Valor do Serviço

                    if (facade.Ocorrencia.ValorServico.HasValue)
                    {
                        var ValorServicoCRM = new CrmMoney(facade.Ocorrencia.ValorServico.Value);
                        entidade = PluginHelper.AdicionarPropriedadeEmEntidadeDinamica(entidade, "new_valor_servico", ValorServicoCRM);
                    }

                    #endregion

                    #endregion
                    PluginHelper.LogEmArquivo(context, "FIM;", inicioExecucao.ToString(), DateTime.Now.ToString());
                }
            }
            catch (Exception ex)
            {
                PluginHelper.TratarExcecao(ex, TipoDeLog.PluginIncident);
                PluginHelper.LogEmArquivo(context, "ERRO;", inicioExecucao.ToString(), DateTime.Now.ToString());
            }
        }