/// <summary> /// Implementation of the Factory Method pattern for creation of a shipping cost object /// </summary> /// <returns></returns> protected override IShippingCost CreateShippingCostCalculator(IOrderConfig orderConfig) { //switch(orderConfig.Data.ToString().ToUpper()) //{ // case "DHL": // return new DhlShippingCost(); // case "FEDEX": // return new FedExShippingCost(); // case "UPS": // return new UpsShippingCost(); // case "USPS": // return new UspsShippingCost(); // default: // // TODO: return "unknown" shipping cost type // return null; //} try { Assembly asm = Assembly.Load("OrderManagement.Lib"); Type shipType = asm.GetType(string.Format("{0}shippingcost", orderConfig.Data.ToString().ToLower()), true, true); IShippingCost obj = Activator.CreateInstance(shipType) as IShippingCost; return obj; } catch (Exception ex) { var msg = ex.Message; } return null; }
public object Process(Order order, IOrderConfig orderConfig) { ShippingCost = CreateShippingCostCalculator(orderConfig); // Factory Method pattern // Decorator pattern - set up the types cost components to be calculated, in the desired order. CostComponent costComponent = new ShippingCostElement(this); costComponent = new IncomeTaxCostElement(costComponent); order.Cost.Total = costComponent.CalculateCostComponent(order); return order; }
public int CreateOrder(IOrderConfig orderConfig, Order order) { if (orderConfig.IsOrderBanned) { return(0); } bool stockStatus = true; foreach (var product in order.Details) { if (!IsStockAvailable(product.ProductId, product.Quantity)) { stockStatus = false; } } if (!stockStatus) { return(0); } return(order.OrderId); }
protected abstract IShippingCost CreateShippingCostCalculator(IOrderConfig orderConfig);