/// <summary> /// This is the method targeted by Unit Tests. /// It contains the BusinessLogic /// </summary> /// <param name="p"></param> /// <param name="orderId"></param> /// <param name="isExecute"></param> /// <param name="exq"></param> public void MapExecutables(Product p, int orderId, bool isExecute, ref Executables exq) { exq = ApplyBusinessRules(p); if (isExecute) { GoExecute(exq, orderId); } }
/// <summary> /// The Main Business Rules will be Applied here /// Rule 1: If Physical Product, Customer Packing Slips Generated /// Rule 2: If Physical Product, Agent Commission Payment need to created /// Rule 3: If Membership Product, Membership either need to be Activated or Upgraded /// Rule 4: If Membership Product send a mail to customer also /// Rule 5: If "Learning to Ski" Video, then "First Aid" video is free with it /// Rule 6: If Book then additional Royalty Department Packing slip need to be generated. /// </summary> /// <param name="p"></param> /// <returns></returns> private Executables ApplyBusinessRules(Product p) { Executables exq = new Executables(); if (p.IsPhysicalProduct) { exq.IsPacking = true; exq.IsPhysicalProduct = true; exq.IsPackingSlipRequired = true; exq.AgentCommission = (int)(p.ProductPrice / 100) * 5; } if (p.IsMembershipProduct) { exq.IsMembership = true; exq.MembershipType.Add(p.ProductMembershipType); } List <Product> products = new List <Product>(); products.Add(p); if (p.IsVideoProduct && p.ProductName == LearningtoSki) { Product p1 = new Product(); p1 = GetProducts().products.FirstOrDefault(x => x.ProductName == FirstAid); products.Add(p1); } exq.Products = products; List <string> slips = new List <string>(); slips.Add(PackingSlip.CustomerShipping.ToString()); if (p.IsBookProduct) { slips.Add(PackingSlip.RoyaltyDepartment.ToString()); } exq.PackingSlips = slips; return(exq); }
/// <summary> /// This is the Final Execution Method. /// This methods directs all the departments to execute a processing /// </summary> /// <param name="exq"></param> /// <param name="orderId"></param> private void GoExecute(Executables exq, int orderId) { if (exq.IsPackingSlipRequired) { GeneratePackingSlips(exq.PackingSlips, orderId); } if (exq.IsPhysicalProduct && exq.Products.Count > 0) { SendToPackingDepartment(exq.Products, orderId); } if (exq.IsPhysicalProduct && exq.AgentCommission > 0) { GenerateCommissionPayment(exq.AgentCommission, orderId); } if (exq.IsMembership) { ApplyTheMembershipAndSendEmail(exq.MembershipType); } }