Пример #1
0
        // GET: MealPlan
        public ActionResult Index()
        {
            MealPlanService service = CreateMealPlanService();
            var             model   = service.GetMealPlans();

            return(View(model));
        }
Пример #2
0
        /// <summary>
        /// This example uses the Abstract Factory creational pattern to help fulfill a meal planning application
        /// for customers who wish to follow a specific type of diet.  Depending on the customer's diet,
        /// a different Meal Plan is generated, which contains methods in this example for generating lunch or dessert menus,
        /// which provide lists of ingredients, meals, and diet summaries.
        /// One of the benefits of this approach is that all of the data associated with a specific diet,
        /// such as the foods involved in meal prep and grocery lists, can belong to specific factories,
        /// increasing the ability to ensure compatibility across the various products of a MealPlanFactory.
        /// One of the downsides of this approach is that it is fairly complex for small use cases, though
        /// it does promote extensibility (Open / Closed principle - open for extension, closed for modification)
        /// if new meal plans are introduced, there is no need clients of the MealPlanService.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private static async Task Main(string[] args)
        {
            var logger = new ConsoleLogger();

            logger.LogInfo("Please enter customer email.");
            var customerEmail = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(customerEmail))
            {
                logger.LogInfo("Error reading customer email.");
                return;
            }

            try {
                var              dietType        = GetCustomerDietFromDatabase(customerEmail);
                var              mealPlanFactory = GetFactoryForDietType(dietType);
                ISendsEmails     emailer         = new Emailer(logger);
                IMealPlanService mealPlanService = new MealPlanService(mealPlanFactory, emailer);
                await mealPlanService.SendDessertsPlanToSubscriber(customerEmail);
            } catch (Exception e) {
                logger.LogError($"{$"Error processing the meal plan: {e.Message}, {e.StackTrace}"}");
                return;
            }

            return;
        }
Пример #3
0
        //HELPER METHODS
        private MealPlanService CreateMealPlanService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new MealPlanService(userId);

            return(service);
        }
Пример #4
0
        public double GetPrice()
        {
            IMealPlan mealPlan  = new MealPlanService().GetMealPlanOrDefault(this);
            double    reduction = new DiscountService().GetOverallReduction(this);

            if (mealPlan != null)
            {
                return(mealPlan.Price + (WithCoffee ? 1 : 0) - reduction);
            }

            return(Meal.Price + Beverage.Price + Dessert.Price + (WithCoffee ? 1 : 0) - reduction);
        }
Пример #5
0
        public ActionResult Create(MealPlanCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            MealPlanService service = CreateMealPlanService();

            if (service.CreateMealPlan(model))
            {
                TempData["SaveResult"] = "Your Meal Plan was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Meal Plan unable to be created.");
            return(View(model));
        }