Ejemplo n.º 1
0
 private Customer CompositeToCustomer(CompositeCustomer comp)
 {
     return(new Customer()
     {
         Name = comp.CustomerName,
         Address = comp.CustomerAddress,
         PhoneNo = comp.CustomerPhoneNo,
         Email = comp.CustomerEmail,
         Zipcode = comp.CustomerZipcode
     });
 }
Ejemplo n.º 2
0
        private CompositeCustomer CustomerToComposite(Customer customer)
        {
            CompositeCustomer compositeCustomer = new CompositeCustomer();

            compositeCustomer.CustomerAddress = customer.Address;
            compositeCustomer.CustomerEmail   = customer.Email;
            compositeCustomer.CustomerZipcode = customer.Zipcode;
            compositeCustomer.CustomerPhoneNo = customer.PhoneNo;

            return(compositeCustomer);
        }
Ejemplo n.º 3
0
        public string ProcessSale(List <CompositeProduct> compProducts, CompositeCustomer compCustomer)
        {
            // Lav Composite objekt om til et "normalt" objekt
            Customer       customer   = CompositeToCustomer(compCustomer);
            List <Product> products   = new List <Product>();
            long           totalPrice = 0;

            // Lokalvariabel til at holde styr på totalprisen for ordren


            // Lav listen af Composite Objekter om til en liste af normale Produkter TEST
            foreach (CompositeProduct compP in compProducts)
            {
                products.Add(CompositeToProduct(compP));
                // For hvert produkt, + prisen til totalprisen
                totalPrice += compP.Price;
            }

            // Lav en Order lokalvariabel, med 7 dages levering
            Order order = new Order(totalPrice, DateTime.Now, DateTime.Now.AddDays(7), customer);

            foreach (Product p in products)
            {
                OrderLine orderLine = new OrderLine();
                orderLine.Product = p;
                order.AddToOrderLine(orderLine);
            }

            try
            {
                return(orderController.ProcessSale(order));
            }
            catch (ProductAlreadyUpdatedException e)
            {
                return(e.Message);
            }
            catch (Exception)
            {
                return("Something went wrong. Please try again");
            }
        }
Ejemplo n.º 4
0
        public void CreateCustomer(CompositeCustomer composite)
        {
            Customer customer = CompositeToCustomer(composite);

            personController.CreateCustomer(customer);
        }