Example #1
0
        public async Task <IActionResult> Index()
        {
            // Fetching Meals into local JArray
            JArray mealArray = await MealMethods.GetMeals();

            // Converting JArray items to Collection object of given type
            List <Meal> meals = mealArray.ToObject <List <Meal> >();

            Domain.Client client = _clientService.GetClientByEmail(User.Identity.Name);
            List <Order>  orders = new List <Order>();

            foreach (var item in _orderService.GetOrders())
            {
                if (item.Client == client)
                {
                    orders.Add(item);
                }
            }

            List <OrderMeal>     orderMeals = _orderService.GetOrderMeals();
            List <OrderMealDish> mealDishes = _orderService.GetOrderMealDishes();


            double birthdayDiscount = 0;

            ViewBag.OrderMeals = orderMeals;
            ViewBag.MealDishes = mealDishes;
            ViewBag.Meals      = meals;
            ViewBag.Birthday   = birthdayDiscount;
            ViewBag.Client     = client;
            return(View(orders));
        }
Example #2
0
        public virtual double ComputeTotalValue(List <CartLine> lines)
        {
            double price = 0;

            foreach (var item in lines)
            {
                price += MealMethods.GetMealPrice(item.Meal);
            }
            return(price);
        }
Example #3
0
        /** WERKT **/
        public async Task <IActionResult> Order()
        {
            if (User.Identity.IsAuthenticated)
            {
                // Fetching Dishes into local JArray
                JArray dishArray = await DishMethods.GetDishes();

                // Converting JArray items to Collection object of given type
                List <Dish> allDishes = dishArray.ToObject <List <Dish> >();

                Dictionary <int, List <Meal> > dict = new Dictionary <int, List <Meal> >();

                foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
                {
                    dict.Add((int)day, new List <Meal>());
                }

                // Parsing the given dates through TempData
                DateTime startDate = DateTime.Parse(TempData["start"].ToString());
                DateTime endDate   = DateTime.Parse(TempData["end"].ToString());

                if (MealMethods.Week(startDate) == MealMethods.Week(endDate))
                {
                    // For each meal in retrieved meals add it to the dictionary by specific day of week
                    foreach (var meal in await MealMethods.GetAllWeekMeals(startDate))
                    {
                        var day = meal.DateValid.DayOfWeek;
                        dict[(int)day].Add(meal);
                    }

                    List <MealDishes> mealDishes = new List <MealDishes>();

                    var dishes = _mealService.MealDish.ToList();

                    foreach (var item in dishes)
                    {
                        mealDishes.Add(item);
                    }

                    ViewBag.MealDishes = mealDishes;
                    ViewBag.Dishes     = allDishes;
                    ViewBag.Dictionary = dict;

                    return(View());
                }

                ModelState.AddModelError(string.Empty, "Application error: could not load the meals");
                return(View());
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Example #4
0
        public IActionResult ChooseWeek(ChooseWeekViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    bool nextWeekStart = MealMethods.Week(model.Start) != (MealMethods.Week(DateTime.Now.Date) + 1) ? true : false;
                    bool nextWeekEnd   = MealMethods.Week(model.End) != (MealMethods.Week(DateTime.Now.Date) + 1) ? true : false;

                    // To check if the begin date / end date is in the same week
                    if (MealMethods.Week(model.Start) != MealMethods.Week(model.End))
                    {
                        ModelState.AddModelError(string.Empty, "The given start date and end date were not in the same week!");
                        return(View());
                    }
                    else if (model.Start > model.End)
                    {
                        ModelState.AddModelError(string.Empty, "You cannot choose an end data that is passed the given start date!");
                        return(View());
                    }
                    //else if (nextWeekStart && nextWeekEnd)
                    //{
                    //    ModelState.AddModelError(string.Empty, "You cannot order for this week only for the next week after the current week!");
                    //    return View();
                    //}
                    else if (model.Start.DayOfWeek != DayOfWeek.Monday || model.End.DayOfWeek != DayOfWeek.Sunday)
                    {
                        ModelState.AddModelError(string.Empty, "You can only order for a full week!");
                        return(View());
                    }
                    else
                    {
                        TempData["start"] = model.Start;
                        TempData["end"]   = model.End;
                        return(RedirectToAction("Order", "Order"));
                    }
                }

                ModelState.AddModelError(string.Empty, "Please fill in both dates to continue");
                return(View());
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
        public void GetMealPriceExtensionMethod()
        {
            meal1.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal2.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };

            double meal1Price = MealMethods.GetMealPrice(meal1);
            double meal2Price = MealMethods.GetMealPrice(meal1);

            Assert.Equal((17.85), meal1Price);
            Assert.Equal((17.85), meal2Price);
        }
        public void Has_BirthDay_Discount()
        {
            Domain.Cart target = new Domain.Cart();
            meal1.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal2.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal3.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };

            target.AddItem(meal2, DateTime.Now.DayOfWeek);
            target.AddItem(meal3, DateTime.Now.DayOfWeek);
            target.AddItem(meal1, DateTime.Now.DayOfWeek);

            var    lines = target.Lines;
            double total = target.ComputeTotalValue(lines);

            Assert.Equal((17.85 * 3), total);

            Domain.Client client = new Domain.Client()
            {
                FirstName = "Tester",
                LastName  = "Test",
                Birthday  = DateTime.Now.Date,
                Email     = "*****@*****.**"
            };

            bool sameDate = target.MealOnBirthDay(client.Birthday);

            Assert.True(sameDate);

            if (sameDate)
            {
                total -= MealMethods.GetMealPrice(meal1);
            }

            Assert.Equal(35.7, total);
        }