Beispiel #1
0
        /// <summary>
        /// Update existing customer information
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public async Task <CustomerStructure> UpdateCustomerAsync(CustomerStructure customer)
        {
            CheckFirst(customer);

            var data = new
            {
                name         = customer.CustomerName ?? string.Empty,
                company_type = customer.CustomerCompanyType ?? "individual",
                org_no       = customer.CustomerOrganizationNo ?? string.Empty,
                contact      = new
                {
                    name  = customer.CustomerContact?.CustomerContactName ?? string.Empty,
                    email = customer.CustomerContact?.CustomerContactEmail ?? string.Empty,
                    phone = customer.CustomerContact?.CustomerContactPhone ?? string.Empty
                },
                address = new
                {
                    street_address = customer.CustomerPrimary?.CustomerPrimaryStreetAddress ?? string.Empty,
                    zipcode        = customer.CustomerPrimary?.CustomerPrimaryZipCode ?? string.Empty,
                    city           = customer.CustomerPrimary?.CustomerPrimaryCity ?? string.Empty,
                    country        = customer.CustomerPrimary?.CustomerPrimaryCountry ?? string.Empty
                },
                delivery_address = new
                {
                    name           = customer.CustomerDelivery?.CustomerDeliveryName ?? string.Empty,
                    street_address = customer.CustomerDelivery?.CustomerDeliveryStreetAddress ?? string.Empty,
                    careof         = customer.CustomerDelivery?.CustomerDeliveryCareOf ?? string.Empty,
                    zipcode        = customer.CustomerDelivery?.CustomerDeliveryZipCode ?? string.Empty,
                    city           = customer.CustomerDelivery?.CustomerDeliveryCity ?? string.Empty,
                    country        = customer.CustomerDelivery?.CustomerDeliveryCountry ?? string.Empty
                }
            };

            HttpResponseMessage response = await _client.PutAsJsonAsync(_baseUrl + "customer/" + customer.CustomerNo, data);

            try
            {
                if (response.IsSuccessStatusCode)
                {
                    response.EnsureSuccessStatusCode();

                    var responseBody = await response.Content.ReadAsStringAsync();

                    JObject jObject      = JObject.Parse(responseBody);
                    JToken  customerData = jObject["data"];
                    _customer = customerData.ToObject <CustomerStructure>();
                }
                else
                {
                    Console.WriteLine("Failed to update data");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Customer info update error message " + e.Message);
            }
            return(_customer);
        }
Beispiel #2
0
        /// <summary>
        /// Check some specific fields if those are required in current condition
        /// </summary>
        /// <param name="obj"></param>
        private static void CheckFirst(CustomerStructure obj)
        {
            Type objtype = obj.GetType();

            foreach (PropertyInfo p in objtype.GetProperties())
            {
                Type type;
                if (p.Name == "CustomerPrimary")
                {
                    type = obj.CustomerPrimary?.GetType();

                    if (type != null)
                    {
                        if (obj.CustomerPrimary?.CustomerPrimaryStreetAddress?.Length < 1)
                        {
                            continue;                                                                                        //c.CheckLength
                        }
                        foreach (PropertyInfo prop in type.GetProperties().Where(prop => prop.Name == "CustomerPrimaryStreetAddress"))
                        {
                            if (obj.CustomerPrimary.CustomerPrimaryZipCode == null || obj.CustomerPrimary.CustomerPrimaryCity == null)
                            {
                                throw new Exception(" Zip code and primary city is required if primary street address is specified ");
                            }
                        }
                    }
                }
                if (p.Name == "CustomerDelivery")
                {
                    type = obj.CustomerDelivery?.GetType();

                    if (type == null)
                    {
                        continue;
                    }
                    if (obj.CustomerDelivery?.CustomerDeliveryStreetAddress?.Length < 1)
                    {
                        continue;
                    }
                    foreach (PropertyInfo prop in type.GetProperties().Where(prop => prop.Name == "CustomerDeliveryStreetAddress"))
                    {
                        if (obj.CustomerDelivery.CustomerDeliveryCity == null || obj.CustomerDelivery.CustomerDeliveryZipCode == null)
                        {
                            throw new Exception(" Zip code and delivery city is required if delivery street address is specified ");
                        }
                    }
                }
            }
        }
        public void UpdateCustomer_Test()
        {
            var cusInfo = _billogramUtility.GetCustomerInfo(1).Result;

            //zipcode required if streeaddress
            cusInfo.CustomerContact = new CustomerContact()
            {
                CustomerContactName = "Wftes"
            }

            ;

            CustomerStructure result = _billogramUtility.UpdateCustomerAsync(cusInfo).Result;


            Assert.AreEqual(result.CustomerContact.CustomerContactName, cusInfo.CustomerContact.CustomerContactName);
        }
Beispiel #4
0
        /// <summary>
        /// Get an existing customer
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        public async Task <CustomerStructure> GetCustomerInfo(int customerId)
        {
            HttpResponseMessage response = await _client.GetAsync(_baseUrl + "customer/" + customerId);

            if (!response.IsSuccessStatusCode)
            {
                return(_customer);
            }
            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            JObject jObject      = JObject.Parse(responseBody);
            JToken  customerData = jObject["data"];

            _customer = customerData.ToObject <CustomerStructure>();

            return(_customer);
        }
Beispiel #5
0
        /// <summary>
        /// Create a customer for specific company
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public async Task <CustomerStructure> CreateCustomer(CustomerStructure customer)
        {
            var data = new
            {
                customer_no = customer.CustomerNo,

                name         = customer.CustomerName ?? string.Empty,
                company_type = customer.CustomerCompanyType ?? "individual",
                org_no       = customer.CustomerOrganizationNo ?? string.Empty,
                contact      = new
                {
                    name  = customer.CustomerContact.CustomerContactName ?? string.Empty,
                    email = customer.CustomerContact.CustomerContactEmail ?? string.Empty,
                    phone = customer.CustomerContact.CustomerContactPhone ?? string.Empty
                },
                address = new
                {
                    street_address = customer.CustomerPrimary.CustomerPrimaryStreetAddress ?? string.Empty,
                    zipcode        = customer.CustomerPrimary.CustomerPrimaryZipCode ?? string.Empty,
                    city           = customer.CustomerPrimary.CustomerPrimaryCity ?? string.Empty,
                    country        = customer.CustomerPrimary.CustomerPrimaryCountry ?? string.Empty
                },
                delivery_address = new
                {
                    name           = customer.CustomerDelivery.CustomerDeliveryName ?? string.Empty,
                    street_address = customer.CustomerDelivery.CustomerDeliveryStreetAddress ?? string.Empty,
                    careof         = customer.CustomerDelivery.CustomerDeliveryCareOf ?? string.Empty,
                    zipcode        = customer.CustomerDelivery.CustomerDeliveryZipCode ?? string.Empty,
                    city           = customer.CustomerDelivery.CustomerDeliveryCity ?? string.Empty,
                    country        = customer.CustomerDelivery.CustomerDeliveryCountry ?? string.Empty
                }
            };

            HttpResponseMessage response = await _client.PostAsJsonAsync(_baseUrl + "customer/", data);

            response.EnsureSuccessStatusCode();
            var responseBody = await response.Content.ReadAsStringAsync();

            JObject json         = JObject.Parse(responseBody);
            JToken  customerData = json["data"];

            _customer = customerData.ToObject <CustomerStructure>();
            return(_customer);
        }
        public void CreateCustomer_Test()
        {
            var model = new CustomerStructure()
            {
                CustomerNo             = 813,
                CustomerName           = "Wftest",
                CustomerCompanyType    = "individual",
                CustomerOrganizationNo = "",
                CustomerVatNo          = "",


                CustomerContact = new CustomerContact()
                {
                    CustomerContactName  = "Wftest Customer",
                    CustomerContactEmail = "*****@*****.**",
                    CustomerContactPhone = "0765707970",
                },
                CustomerDelivery = new CustomerDelivery()
                {
                    CustomerDeliveryName          = "Wftest Customer",
                    CustomerDeliveryCareOf        = "Wftest",
                    CustomerDeliveryZipCode       = "16962",
                    CustomerDeliveryStreetAddress = "Regeringsgatan 65",
                    CustomerDeliveryCity          = "Stockholm",
                    CustomerDeliveryCountry       = "SE",
                },
                CustomerPrimary = new CustomerPrimary()
                {
                    CustomerPrimaryStreetAddress        = "Regeringsgatan 65",
                    CustomerPrimaryZipCode              = "16962",
                    CustomerPrimaryCity                 = "Stockholm",
                    CustomerPrimaryCountry              = "bd",
                    CustomerPrimaryCareOf               = "Wftest",
                    CustomerPrimaryUseCareOfAsAttention = true,
                }
            };
            CustomerStructure result = _billogramUtility.CreateCustomer(model).Result;

            Assert.IsNotNull(result.CustomerNo);
        }
Beispiel #7
0
        public static void Main(string[] args)
        {
            var e = new AdditionExpression(
                new DoubleExpression(1),
                new AdditionExpression(
                    new DoubleExpression(2),
                    new DoubleExpression(3)));

            var ep = new ExpressionPrinter();

            ep.Visit(e);
            Console.WriteLine(ep);

            var calc = new ExpressionCalculator();

            calc.Visit(e);
            Console.WriteLine($"{ep} = {calc.Result}");

            Console.WriteLine("Taxi Visitor!");


            CustomerStructure o = new CustomerStructure();

            o.Attach(new TaxiCustomer("Andrzej"));
            o.Attach(new TaxiCustomer("Seba"));
            o.Attach(new TaxiCustomer("Pudzian"));
            o.Attach(new RichCustomer("Musk"));
            o.Attach(new PoorCustomer("Żul"));

            Taxi t1 = new Taxi1();
            Taxi t2 = new Taxi2();

            o.Accept(t1);

            Console.WriteLine();

            o.Accept(t2);


            Console.WriteLine("Acyclic visitor");


            var expression = new AcyclicVisitor.AdditionExpression(
                new AcyclicVisitor.DoubleExpression(1),
                new AcyclicVisitor.AdditionExpression(
                    new AcyclicVisitor.DoubleExpression(2),
                    new AcyclicVisitor.DoubleExpression(3)));

            var acyclic_ep = new AcyclicVisitor.ExpressionPrinter();

            acyclic_ep.Visit(expression);
            Console.WriteLine(acyclic_ep.ToString());


            Console.WriteLine();

            Console.WriteLine("Code exercise");

            var simple      = new Coding.Exercise.AdditionExpression(new Coding.Exercise.Value(2), new Coding.Exercise.Value(3));
            var exercise_ep = new Coding.Exercise.ExpressionPrinter();

            exercise_ep.Visit(simple);

            Console.WriteLine(exercise_ep.ToString());


            Console.ReadLine();
        }