public override KombuchaSale Handle(KombuchaSale request) { if (request.SaleType == SaleType.InHouse) { _logger.LogInfo("Printing receipt for in-house order.", ConsoleColor.Green); return(base.Handle(request)); } if (request.SaleType != SaleType.Online) { return(base.Handle(request)); } _logger.LogInfo("Emailing receipt for online order.", ConsoleColor.Green); var emailReceipt = new EmailMessage("*****@*****.**", "Here's your receipt."); if (request.SpecialMessages != null && request.SpecialMessages.Any()) { foreach (var message in request.SpecialMessages) { emailReceipt.Content += $"| {message}"; } } var emailTask = _emailer.SendMessage(emailReceipt); emailTask.Wait(); return(base.Handle(request)); }
/// <summary> /// We run a company that brews and bottles kombucha. As part of our checkout process, bottles /// of the product follow different paths depending on type of sale initiated. /// We have several business processes to consider as part of our process, /// including accepting in-store and online orders. We also have an Awards Program which /// we'd like to promote to non-Awards members only. Here we use the Chain of Responsibility /// Pattern to process each stage of the sale accordingly. /// </summary> private static void Main() { var logger = new ConsoleLogger(); logger.LogInfo("🍾 Welcome to the Kombucha Checkout System!"); var emailer = new Emailer(logger); var cartonizer = new Cartonizer(logger); var customerLoyalty = new CustomerLoyaltyHandler(logger); var receiptPrinter = new ReceiptPrinter(emailer, logger); var shippingLabeler = new ShippingLabelPrinter(logger); cartonizer .SetNext(customerLoyalty) .SetNext(shippingLabeler) .SetNext(receiptPrinter); logger.LogInfo("Process: Cartonize > Loyalty Program > Shipping Labels > Receipt", ConsoleColor.Blue); logger.LogInfo("----------------------------------------------------------------", ConsoleColor.DarkBlue); var request = new KombuchaSale(); logger.LogInfo("Are you a rewards member? (y/n)", ConsoleColor.Blue); var isRewardsMember = Console.ReadLine(); if (isRewardsMember != null && isRewardsMember.ToLower() == "y") { request.CustomerType = CustomerType.RewardsMember; } else { request.CustomerType = CustomerType.WalkIn; } logger.LogInfo("Is this an online order? (y/n)", ConsoleColor.Blue); var isOnlineOrder = Console.ReadLine(); if (isOnlineOrder != null && isOnlineOrder.ToLower() == "y") { request.SaleType = SaleType.Online; } else { request.SaleType = SaleType.InHouse; } cartonizer.Handle(request); }
public override KombuchaSale Handle(KombuchaSale request) { if (request.SaleType == SaleType.InHouse) { return(base.Handle(request)); } if (request.SaleType == SaleType.Online) { _logger.LogInfo("Printing shipping label for online order.", ConsoleColor.Green); return(base.Handle(request)); } return(base.Handle(request)); }
public override KombuchaSale Handle(KombuchaSale request) { if (request.SaleType == SaleType.InHouse) { return(base.Handle(request)); } if (request.SaleType != SaleType.Online) { return(base.Handle(request)); } _logger.LogInfo("Cartonizing online order.", ConsoleColor.Green); return(base.Handle(request)); }
public override KombuchaSale Handle(KombuchaSale request) { if (request.CustomerType == CustomerType.RewardsMember) { _logger.LogInfo("Adding rewards point for purchase!", ConsoleColor.Green); return(base.Handle(request)); } if (request.CustomerType != CustomerType.RewardsMember) { _logger.LogInfo("Adding advertisement to request.", ConsoleColor.Green); request.SpecialMessages.Add("Have you heard about our Rewards Program?"); return(base.Handle(request)); } Console.ResetColor(); return(base.Handle(request)); }
public virtual KombuchaSale Handle(KombuchaSale request) { return(_nextHandler?.Handle(request)); }