Ejemplo n.º 1
0
        public ReferenceValue GetValue(int attributeValueId)
        {
            var attributeValue = _attributeValueRepository.GetById(attributeValueId);

            if (attributeValue != null)
            {
                var value = new ReferenceValue();
                switch (attributeValue.CustomerInformationProductAttribute.CustomerFieldName)
                {
                case "CityId":
                {
                    var city = _cityService.GetById(attributeValue.ReferenceValueInt.Value);
                    if (city == null)
                    {
                        return(null);
                    }

                    value.Id   = city.Id;
                    value.Text = city.Title;
                    return(value);
                }

                case "Gender":
                {
                    if (attributeValue.ReferenceValueInt == 0)
                    {
                        value.Id   = 0;
                        value.Text = "Ж";
                    }
                    else
                    {
                        value.Id   = 1;
                        value.Text = "М";
                    }

                    return(value);
                }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public ReferenceValue GetCustomerAttribute(int attributeId, Customer customer)
        {
            var attribute      = _attributesRepository.GetById(attributeId);
            var referenceValue = new ReferenceValue();

            switch (attribute.CustomerFieldName)
            {
            case "Income":
            {
                if (customer.Income.HasValue)
                {
                    var currency = _currencyService.GetCurrencyById(customer.CurrencyId.Value);
                    int value    = (int)(customer.Income.Value * (double)currency.Rate);
                    referenceValue.Text = value.ToString();
                    referenceValue.Id   = currency.Id;
                }
                break;
            }

            case "BirthdayDate":
            {
                if (customer.BirthdayDate.HasValue)
                {
                    DateTime today = DateTime.Today;
                    int      age   = today.Year - customer.BirthdayDate.Value.Year;
                    if (customer.BirthdayDate.Value > today.AddYears(-age))
                    {
                        age--;
                    }
                    referenceValue.Text = age.ToString();
                }
                break;
            }
            }
            return(referenceValue);
        }