public static bool?Convert(CrmBoolean obj)
 {
     return(obj.IsNull == false ? (bool?)obj.Value : null);
 }
Exemple #2
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;
            }
        }
        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")
                });
            }
        }