public static IPwsObjectWrapper <NavigationChoice_V1> Navigate(this IPwsObjectWrapper <NavigationChoice_V1> choice, String categoryKey, String categoryValue)
 {
     return(RESTHandler <IPwsObjectWrapper <NavigationChoice_V1> > .Invoke(
                () => choice.Follow <NavigationChoice_V1>(f => f.NextChoices.Where(fl => fl.ClassificationName == categoryKey).First().Categories.Where(fl => fl.CategoryName == categoryValue).First().NavigationChoice),
                "Product Navigation"
                ));
 }
 public static IPwsObjectWrapper <ProductInformation_V1>[] Products(this IPwsObjectWrapper <NavigationChoice_V1> choice)
 {
     return(RESTHandler <IPwsObjectWrapper <ProductInformation_V1>[]> .Invoke(
                () => choice.FollowList <ProductInformation_V1>(f => f.ProductList).ToArray(),
                "Product List"
                ));
 }
 public static IPwsObjectWrapper <OrderLine_V1> AddLine(this IPwsObjectWrapper <Order_V1> order, String productId, decimal quantity)
 {
     return(RESTHandler <IPwsObjectWrapper <OrderLine_V1> > .Invoke(() => order.Post(f => f.Lines, new OrderLine_V1()
     {
         ProductId = productId, OrderQuantity = quantity
     }), "Add Order Line"));
 }
        public static IPwsObjectWrapper <OrderLine_V2> AddBespokeLine(this IPwsObjectWrapper <Order_V1> order, String productId, CustomerBespokeLineOption options, decimal quantity)
        {
            var line = order.AddBespokeLine(productId, quantity);

            while (line.PwsObject.NextBespokeOption != null)
            {
                String  selectionCode     = null;
                decimal?selectionQuantity = null;

                if (options.TryGetOption(line.PwsObject.NextBespokeOption.TypeCode, line.PwsObject.NextBespokeOption.Selection?.Description, out selectionCode, out selectionQuantity) == false)
                {
                    throw new Exception("No option provided for question: " + line.PwsObject.NextBespokeOption.TypeCode + ":" + line.PwsObject.NextBespokeOption.Description + ".");
                }

                var selection = line.PwsObject.NextBespokeOption.Selection ?? line.PwsObject.NextBespokeOption.Options.Where(f => f.OptionCode == selectionCode).FirstOrDefault();
                if (selection == null)
                {
                    throw new Exception("Invalid option value '" + selectionCode + "' for question: " + line.PwsObject.NextBespokeOption.TypeCode + ":" + line.PwsObject.NextBespokeOption.Description + ".");
                }

                line = order.AddBespokeLine(line.PwsObject, selection, selectionQuantity);
            }

            return(line);
        }
 public static IPwsObjectWrapper <Contact_V1> AssignBuyerContact(this IPwsObjectWrapper <Order_V1> order, String firstname, String surname)
 {
     return(RESTHandler <IPwsObjectWrapper <Contact_V1> > .Invoke(() => order.Put(f => f.BuyerContact, new Contact_V1()
     {
         FirstName = firstname, Surname = surname
     }), "Assign Buyer Contact Name to Order"));
 }
 public static IPwsObjectWrapper <Order_V1> Create(IPwsObjectWrapper <Customer_V1> customer, String uniqueReference)
 {
     return(RESTHandler <IPwsObjectWrapper <Order_V1> > .Invoke(() => customer.Post(f => f.OutstandingOrders, new Order_V1()
     {
         OrderReference = uniqueReference
     }), "Create Order"));
 }
 public static IPwsObjectWrapper <Category_V1>[] Categories(this IPwsObjectWrapper <ProductInformation_V1> info)
 {
     return(RESTHandler <IPwsObjectWrapper <Category_V1>[]> .Invoke(
                () => info.FollowList <Category_V1>(f => f.Categories).ToArray(),
                "Category List"
                ));
 }
 public static IPwsObjectWrapper <Contact_V1> Create(IPwsObjectWrapper <Customer_V1> customer, String title, String firstname, String surname, String jobTitle, String emailAddress)
 {
     return(RESTHandler <IPwsObjectWrapper <Contact_V1> > .Invoke(() => customer.Post(f => f.Contacts, new Contact_V1()
     {
         Title = title, FirstName = firstname, Surname = surname, JobTitle = jobTitle, Email = new Uri("mailto://" + emailAddress)
     }), "Create Customer Contact"));
 }
 public static IPwsObjectWrapper <OrderLine_V2> AddBespokeLine(this IPwsObjectWrapper <Order_V1> order, String productId, decimal quantity)
 {
     return(RESTHandler <IPwsObjectWrapper <OrderLine_V2> > .Invoke(() => order.Post(f => f.Lines, new OrderLine_V2()
     {
         ProductId = productId, OrderQuantity = quantity, IgnoreBespokeOptionDefaults = true
     }), "Add Bespoke Order Line"));
 }
        public static void Run(IPwsObjectWrapper <Customer_V1> customer)
        {
            Console.WriteLine("Demonstrate Order Batching.");

            // Create basics of a master order
            var newOrderMaster = CustomerOrder.Create(customer, "TESTA" + DateTime.Now.ToString("yyyyMMddHHmmss"));

            newOrderMaster.AddLine("3203", 96);

            // Create basics of a related order
            var newOrderToConsolidate = CustomerOrder.Create(customer, "TESTB" + DateTime.Now.ToString("yyyyMMddHHmmss"));

            newOrderToConsolidate.AddLine("3203", 96);

            // Create new batch by adding second order to first order
            var newBatch = newOrderMaster.Batch().AddToBatch(newOrderToConsolidate.PwsObject.OrderId);

            // Retrieve all outstanding jobs (aka master orders)
            var batchedJobs = CustomerOrder.GetOutstandingJobs(customer);

            // Now try removing the second order from batch, which should close it
            var UpdatedBatch = newOrderMaster.Batch().RemoveFromBatch(newOrderToConsolidate.PwsObject.OrderId);

            // Retrieve all outstanding jobs (aka master orders)
            var batchedJobsAfterRemoval = CustomerOrder.GetOutstandingJobs(customer);

            Console.WriteLine("Completed.");
        }
        public static void Run(IPwsObjectWrapper <Customer_V1> customer)
        {
            Console.WriteLine("Demonstrate Product Navigation.");

            // Products are filtered using Navigation.
            var root = Product.GetChoices(customer);

            // We can retrieve a list of filter choices
            var availableFilters = root.PwsObject.NextChoices;

            // We can apply filters in any order, but here start with 'Kitchen' room.
            var kitchen = root.Navigate("Room", "Kitchen");

            // Can check what choices we've made so far
            var appliedFilters = kitchen.PwsObject.PreviousChoices;

            // Now let us filter a little further to the 'Broadoak Natural' Kitchen range
            var broadoak = kitchen.Navigate("Section", "Doors").Navigate("Range", "Broadoak Natural");

            // From Broadoak we can retrieve a list of all contained within that Navigation, containing specific prices for this customer.
            var products = broadoak.ProductsWithPrices();

            // Once a few filters are applied, there is a roll-up of navigations into useful product sets
            var rollup = broadoak.RollupWithProductsAndPrices();

            // Now that we have a list of products let us fetch some information about the first product in the list.
            // Staring with a list of individual details (i.e. dimensions, colour, finish, style, etc.)
            var categories = products.First().Categories();

            // How about some pricing and availability details
            var product   = products.First().PwsObject.CustomerProduct_V1;
            var stock     = product.Price.AvailableQuantity;
            var available = product.Price.AvailableDate;
            var gross     = product.Price.GrossPrice;
            var discount  = product.Price.DiscountPercentage;
            var net       = product.Price.NetPrice;

            // Now lets make an enquiry against a Porter dynamic kit and retrieve a price
            var porterDynamic          = kitchen.Navigate("Section", "Doors").Navigate("Range Family", "Porter");
            var firstPorterBespokeItem = porterDynamic.ProductsWithPrices().Where(f => f.PwsObject.IsBespoke).FirstOrDefault();

            if (firstPorterBespokeItem != null)
            {
                var porterBespokeItem = firstPorterBespokeItem.BespokeKit();
                while (porterBespokeItem.PwsObject.NextBespokeOption != null)
                {
                    porterBespokeItem = firstPorterBespokeItem.BespokePricing(porterBespokeItem.PwsObject, porterBespokeItem.PwsObject.NextBespokeOption.Options.Last(), porterBespokeItem.PwsObject.NextBespokeOption.Selection?.MinQuantity);
                }

                var price = porterBespokeItem.PwsObject.Price;
            }

            // Alternatively you can retrieve a product
            var product3203 = Product.GetProductWithPrice(customer, "3203");
            var pricing     = product3203.PwsObject.Price;
            var multiple    = pricing.OrderMultiple;

            Console.WriteLine("Completed.");
        }
        public static IPwsObjectWrapper <Batch_V1> AddToBatch(this IPwsObjectWrapper <Batch_V1> batch, String orderId)
        {
            RESTHandler <IPwsObjectWrapper <BatchOrder_V1> > .Invoke(() => batch.Post(f => f.Lines, new BatchOrder_V1()
            {
                OrderId = orderId
            }), "Add Batch Order");

            return(RESTHandler <IPwsObjectWrapper <Batch_V1> > .Invoke(() => batch.Refresh(), "Refresh Batch"));
        }
        public static IPwsObjectWrapper <Order_V1> Release(this IPwsObjectWrapper <Order_V1> order)
        {
            var releaseMethods      = order.FollowList <Release_V1>(f => f.AvailableReleaseMethods);
            var chosenReleaseMethod = releaseMethods.Where(f => f.PwsObject.IsExternalPaymentMethod == false).First();

            RESTHandler <IPwsObjectWrapper <Release_V1> > .Invoke(() => order.Post(f => f.ReleaseMethod, chosenReleaseMethod.PwsObject), "Release Order");

            return(RESTHandler <IPwsObjectWrapper <Order_V1> > .Invoke(() => order.Refresh(), "Release Order Refresh"));
        }
 public static IPwsObjectWrapper <Address_V1> AssignAddress(this IPwsObjectWrapper <Order_V1> order, String name, String line1, String line2, String line3, String line4, String line5, String postcode)
 {
     return(RESTHandler <IPwsObjectWrapper <Address_V1> > .Invoke(() => order.Put(f => f.DeliveryAddress,
                                                                                  new Address_V1()
     {
         AccountCode = String.Empty, AddressNumber = String.Empty, Name = name, Line1 = line1, Line2 = line2, Line3 = line3, Line4 = line4, Postcode = postcode
     }
                                                                                  ), "Assign Manual Address to Order"));
 }
        public static IPwsObjectWrapper <BespokeKit_V1> AddBespokeDrilling(this IPwsObjectWrapper <OrderLine_V2> line)
        {
            if (GetDrillingKit(line) == null)
            {
                return(null);
            }

            return(line.Post(f => GetDrillingKit(line), new BespokeKit_V1()));
        }
        public static void Run(IPwsObjectWrapper <Customer_V1> customer)
        {
            Console.WriteLine("Demonstrate Order Retrieval/ Progress.");

            // Retrieve a list of outstanding orders.
            var orders = CustomerOrder.GetOutstanding(customer).Where(f => f.PwsObject.IsUpdateableByCustomer == false).ToArray();

            // Navigate through each order
            foreach (var order in orders)
            {
                // Get order identity and placement date
                var orderId   = order.PwsObject.OrderId;
                var orderDate = order.PwsObject.OrderDate;
                var reference = order.PwsObject.OrderReference;

                // Get order and payment status
                var status  = order.PwsObject.Status;
                var payment = order.PwsObject.IsPaymentRequired;

                // Get delivery details
                var deliveryAddress = order.Address();
                var deliveryMethod  = order.DispatchMethod();
                var expectedDate    = deliveryMethod.PwsObject.ExpectedDate;

                // Get order totals
                var goodsTotal    = order.PwsObject.GoodsTotal;
                var discountTotal = order.PwsObject.DiscountTotal;
                var carriageTotal = order.PwsObject.CarriageTotal;
                var orderTotal    = order.PwsObject.OrderTotal;

                // Orders are broken up into fulfillments, which are then handled by separate
                // parts of the business.  Sometimes a separate fulfillment will be raised to
                // fulfill a back order, or if more is added to an order after it is released.
                foreach (var fullfilment in order.Progress().PwsObject.Fulfilments)
                {
                    // Each fulfillment is represented here by a set of events (also made up of tasks).
                    foreach (var task in fullfilment.Events)
                    {
                        var dated       = task.DateTime;
                        var description = task.Description;
                        var isComplete  = task.IsCompleted;

                        // If there a link to a binary file then download it
                        if (task.Link?.MediaType.ToLower() == "application/pdf")
                        {
                            var title = task.Link.Title;
                            var file  = Model.Token.GetNewToken().BinaryFile(task.Link);
                            System.Diagnostics.Process.Start(file.FullName);
                        }
                    }
                }
            }

            Console.WriteLine("Completed.");
        }
        public static IPwsObjectWrapper <Product_V2> BespokeKit(this IPwsObjectWrapper <ProductInformation_V1> info)
        {
            var link = info.PwsObject.CustomerBespokeKits.Where(f => f.Href.AbsolutePath.ToLower().EndsWith("bespokekit")).FirstOrDefault();

            if (link == null)
            {
                return(null);
            }

            return(RESTHandler <IPwsObjectWrapper <Product_V2> > .Invoke(() => info.Post(f => link, new Product_V2()
            {
            }), "Bespoke Kit"));
        }
        public static IPwsObjectWrapper <OrderLine_V2> AddBespokeLine(this IPwsObjectWrapper <Order_V1> order, OrderLine_V2 line, BespokeKit_V1.BespokeOption.BespokeSelection selection, decimal?selectionQuantity = null)
        {
            if (line.NextBespokeOption == null)
            {
                throw new Exception("All bespoke options assigned.");
            }

            line.NextBespokeOption.Selection = selection;
            if (selectionQuantity != null)
            {
                line.NextBespokeOption.Selection.Quantity = selectionQuantity;
            }

            return(RESTHandler <IPwsObjectWrapper <OrderLine_V2> > .Invoke(() => order.Post(f => f.Lines, line), "Add Bespoke Order Line"));
        }
        public static IPwsObjectWrapper <Product_V2> BespokePricing(this IPwsObjectWrapper <ProductInformation_CustomerProduct_V1V1> info, Product_V2 product, BespokeKit_V1.BespokeOption.BespokeSelection selection, decimal?selectionQuantity = null)
        {
            if (product.NextBespokeOption == null)
            {
                throw new Exception("All bespoke options assigned.");
            }

            product.NextBespokeOption.Selection = selection;
            if (selectionQuantity != null)
            {
                product.NextBespokeOption.Selection.Quantity = selectionQuantity;
            }

            return(RESTHandler <IPwsObjectWrapper <Product_V2> > .Invoke(() => info.Post(f => product.FindSelfLink(), product), "Bespoke Pricing"));
        }
        public static IPwsObjectWrapper <DispatchMethod_V1> AssignDispatchMethod(this IPwsObjectWrapper <Order_V1> order, String type, DateTime?required)
        {
            var selectedDispatchMethod = order.DispatchMethods().Where(f => f.PwsObject.Type == type).FirstOrDefault()?.PwsObject;

            if (selectedDispatchMethod == null)
            {
                throw new Exception("No matching dispatch method available.");
            }
            if (selectedDispatchMethod.IsDateRequired && required == null)
            {
                throw new Exception("Selected dispatch method requires date.");
            }

            if (required != null)
            {
                selectedDispatchMethod.SelectedDate = required;
            }

            return(RESTHandler <IPwsObjectWrapper <DispatchMethod_V1> > .Invoke(() => order.Put <DispatchMethod_V1>(f => f.SelectedDispatchMethod, selectedDispatchMethod), "Assign Dispatch Method to Order"));
        }
 public static IPwsObjectWrapper <Contact_V1> Update(this IPwsObjectWrapper <Contact_V1> contact)
 {
     return(RESTHandler <IPwsObjectWrapper <Contact_V1> > .Invoke(() => contact.PutSelf(), "Update Customer Contact"));
 }
 public static IPwsObjectWrapper <OrderLine_V1>[] GetLines(this IPwsObjectWrapper <Order_V1> order)
 {
     return(RESTHandler <IPwsObjectWrapper <OrderLine_V1>[]> .Invoke(() => order.FollowList <OrderLine_V1>(f => f.Lines).ToArray(), "Get Order Lines"));
 }
        public static IPwsObjectWrapper <NavigationChoice_ProductInformation_CustomerProduct_V1V1V1>[] RollupWithProductsAndPrices(this IPwsObjectWrapper <NavigationChoice_V1> choice)
        {
            if (choice.PwsObject.NavigationList == null)
            {
                throw new Exception("Product Navigation Rollup not available.");
            }

            return(RESTHandler <IPwsObjectWrapper <NavigationChoice_ProductInformation_CustomerProduct_V1V1V1>[]> .Invoke(
                       () => choice.FollowList <NavigationChoice_ProductInformation_CustomerProduct_V1V1V1>(f => f.NavigationList).ToArray(),
                       "Product Navigation Rollup"
                       ));
        }
 public static void Cancel(this IPwsObjectWrapper <OrderLine_V1> line)
 {
     RESTHandler <object> .Invoke(() => { line.DeleteSelf(); return(null); }, "Cancel Order Line");
 }
 public static IPwsObjectWrapper <Product_V1> GetProductWithPrice(IPwsObjectWrapper <Customer_V1> customer, String productCode)
 {
     return(RESTHandler <IPwsObjectWrapper <Product_V1> > .Invoke(() => customer.FollowList <Product_V1>(f => f.Products, "filter=ProductId Eq '" + productCode + "'").FirstOrDefault(), "Product"));
 }
 public static IPwsObjectWrapper <NavigationChoice_V1> GetChoices(IPwsObjectWrapper <Customer_V1> customer)
 {
     return(RESTHandler <IPwsObjectWrapper <NavigationChoice_V1> > .Invoke(() => customer.Follow <NavigationChoice_V1>(f => f.ProductNavigation), "Product Navigation"
                                                                           ));
 }
Example #27
0
 public static IPwsObjectWrapper <Contact_V1>[] Contacts(this IPwsObjectWrapper <Customer_V1> customer)
 {
     return(RESTHandler <IPwsObjectWrapper <Contact_V1>[]> .Invoke(() => customer.FollowList <Contact_V1>(f => f.Contacts).ToArray(), "Contacts"));
 }
Example #28
0
 public static IPwsObjectWrapper <Address_V1>[] Addresses(this IPwsObjectWrapper <Customer_V1> customer)
 {
     return(RESTHandler <IPwsObjectWrapper <Address_V1>[]> .Invoke(() => customer.FollowList <Address_V1>(f => f.Addresses).ToArray(), "Addresses"));
 }
Example #29
0
 public static IPwsObjectWrapper <Customer_V1> GetCustomerAccount(IPwsObjectWrapper <Token_V1> token, String accountCode)
 {
     return(RESTHandler <IPwsObjectWrapper <Customer_V1> > .Invoke(() => token.FollowList <Customer_V1>(f => f.SecondaryCustomers, "filter=AccountCode Eq '" + accountCode + "'").FirstOrDefault(), "Customer"));
 }
Example #30
0
 public static IPwsObjectWrapper <Customer_V1> GetPrimary(IPwsObjectWrapper <Token_V1> token)
 {
     return(RESTHandler <IPwsObjectWrapper <Customer_V1> > .Invoke(() => token.Follow <Customer_V1>(f => f.PrimaryCustomer), "Customer"));
 }