public virtual coreDto.TaxEvaluationContext ToTaxEvaluationContextDto(TaxEvaluationContext taxContext)
        {
            var retVal = new coreDto.TaxEvaluationContext();

            retVal.InjectFrom <NullableAndEnumValueInjecter>(taxContext);
            if (taxContext.Address != null)
            {
                retVal.Address = taxContext.Address.ToCoreAddressDto();
            }
            if (taxContext.Customer != null)
            {
                retVal.Customer            = taxContext.Customer.ToCoreContactDto();
                retVal.Customer.MemberType = "Contact";
            }
            if (taxContext.Currency != null)
            {
                retVal.Currency = taxContext.Currency.Code;
            }

            retVal.Lines = new List <coreDto.TaxLine>();
            if (!taxContext.Lines.IsNullOrEmpty())
            {
                foreach (var line in taxContext.Lines)
                {
                    var serviceModelLine = new coreDto.TaxLine();
                    serviceModelLine.InjectFrom <NullableAndEnumValueInjecter>(line);
                    serviceModelLine.Amount = (double)line.Amount.Amount;
                    serviceModelLine.Price  = (double)line.Price.Amount;

                    retVal.Lines.Add(serviceModelLine);
                }
            }
            return(retVal);
        }
Esempio n. 2
0
        public static coreDto.TaxEvaluationContext ToTaxEvaluationContextDto(this TaxEvaluationContext taxContext)
        {
            var retVal = new coreDto.TaxEvaluationContext();

            retVal.Code = taxContext.Code;
            retVal.Id   = taxContext.Id;
            retVal.Type = taxContext.Type;

            if (taxContext.Address != null)
            {
                retVal.Address = taxContext.Address.ToCoreAddressDto();
            }

            retVal.Customer = taxContext?.Customer?.Contact?.ToCoreContactDto();
            if (retVal.Customer != null)
            {
                retVal.Customer.MemberType = "Contact";
            }

            if (taxContext.Currency != null)
            {
                retVal.Currency = taxContext.Currency.Code;
            }

            retVal.Lines = new List <coreDto.TaxLine>();
            if (!taxContext.Lines.IsNullOrEmpty())
            {
                foreach (var line in taxContext.Lines)
                {
                    var serviceModelLine = new coreDto.TaxLine
                    {
                        Id       = line.Id,
                        Code     = line.Code,
                        Name     = line.Name,
                        Quantity = line.Quantity,
                        TaxType  = line.TaxType,
                        Amount   = (double)line.Amount.Amount,
                        Price    = (double)line.Price.Amount
                    };

                    retVal.Lines.Add(serviceModelLine);
                }
            }
            return(retVal);
        }