在Shopware Customer Api中发布带有列表的类对象

时间:2019-12-19 10:23:00

标签: c# asp.net-mvc api shopware

我想将带有列表的数据发布到Shopware客户api。当我使用JSON转换类对象时,列表未包含在所有其他数据中。但是我没有得到如何将我的列表与所有类对象数据绑定并通过api发送到的信息。 我想像下面的例子一样发送数据

{
    "email": "meier@mail.de",
    "firstname": "Max",
    "lastname": "Meier",
    "salutation": "mr",
    "billing": {
        "firstname": "Max",
        "lastname": "Meier",
        "salutation": "mr",
        "street": "Musterstrasse 55",
        "city": "Sch\\u00f6ppingen",
        "zipcode": "48624",
        "country": 2
    }
}

这是我的班级

    public class Customer
    {
        public string email;
        public string salutation;
        public string title;
        public string firstname;
        public string lastname;
        public string street;
        public string city;
        public string zipcode;
        public int country;

        private List<Customer> billing;

        public Customer()
        {
        }

        public Customer(List<Customer> billing)
        {
            this.billing = billing;
        }
    }

控制器

            List<Customer> billing = new List<Customer>();
                            billing.Add(new Customer()
                            {
                                firstname = "Hassas",
                                lastname = "sssss",
                                salutation = "mr",
                                street = "Haupt Str 11",
                                city = "abcddd",
                                zipcode = "4900",
                                country = 2
                            });
                            var shopCustomer = new Customer(billing);
                            shopCustomer.firstname = customers.FirstName;
                            shopCustomer.lastname = customers.LastName;
                            shopCustomer.email = customers.Email;
                            shopCustomer.salutation = "mr";

                            customershopwareApi.getCustomerRessource().add(shopCustomer);

1 个答案:

答案 0 :(得分:0)

     Customer customer = new Customer();
        customer.email = "abc@gmail.com";
        customer.firstname = "abc";
        customer.lastname = "defg";
        customer.salutation = "mr";

        Billing billing = new Billing
        {
            firstname = "abc",
            lastname = "defgh",
            salutation = "mr",
            street = "Haupt str 11",
            city = "Hieer",
            zipCode = "4176",
            country = 2
        };
        customer.billing = billing;
        shopwareApi.getCustomerRessource().add(customer);