示例#1
0
        public void Order_Price_Multiple_Returns_Valid()
        {
            // Arrange
            DateTime activeMonday;

            if ((int)DateTime.Today.DayOfWeek == 0)
            {
                activeMonday = DateTime.Today.AddDays(-6);
            }
            else
            {
                activeMonday = DateTime.Today.AddDays(1 - (int)DateTime.Today.DayOfWeek);
            }

            Order order = new Order();

            order.OrderedMeals.Add(new OrderedMeal
            {
                MealDate   = activeMonday,
                TotalPrice = (decimal)10.50
            });
            order.OrderedMeals.Add(new OrderedMeal
            {
                MealDate   = activeMonday.AddDays(1),
                TotalPrice = (decimal)20.25
            });
            DetailedOrderViewModel viewModel = new DetailedOrderViewModel(order);

            // Act
            decimal price = viewModel.CalculateTotalPrice();

            // Assert
            Assert.Equal((decimal)30.75, price);
        }
示例#2
0
        public ActionResult ViewCart(int id = 0)
        {
            double price = 0;
            List <Domain.Model.Item> orderItemsList = new List <Domain.Model.Item>();

            foreach (var val in MyOrder.itemsInOrder)
            {
                orderItemsList.Add(RepoItem.GetItemById(val));
                price = price + RepoItem.GetItemById(val).Price;
            }
            if (id > 0)
            {
                MyOrder.itemsInOrder.Add(id);
                orderItemsList.Add(RepoItem.GetItemById(id));
                price = price + RepoItem.GetItemById(id).Price;
            }
            var viewModel = new DetailedOrderViewModel
            {
                PersonName    = MyOrder.Username,
                StoreName     = RepoStore.GetStoreById(RepoPers.GetPeopleByName(MyOrder.Username).First(p => p.Username.ToLower() == MyOrder.Username.ToLower()).StoreId).Name,
                DateOfOrder   = DateTime.Now,
                Price         = price,
                ItemList      = orderItemsList,
                SuggestedItem = GetSuggestedItem.Suggest(RepoItem, RepoStore, RepoOrd, RepoTopi, RepoSell, RepoPers, RepoRev, MyOrder)
            };

            return(View(viewModel));
        }
示例#3
0
        public async Task <IActionResult> EditOrder(DateTime startDate)
        {
            System.Diagnostics.Debug.WriteLine("Received date: " + startDate);

            Customer customer = await repository.GetCustomer(userManager, HttpContext);

            ViewData["customerName"] = customer.Name;

            bool OrderPhaseActive = (int)DateTime.Today.DayOfWeek > 0 &&
                                    (int)DateTime.Today.DayOfWeek < 5;

            // Check if any order can be editted today
            OrderPhaseActive = true;
            if (!OrderPhaseActive)
            {
                String         message        = "Bestelling kunnen alleen van maandag t/m donderdag gewijzigd worden";
                ErrorViewModel errorViewModel = new ErrorViewModel
                {
                    Message      = message,
                    ReturnAction = "Index"
                };
                return(View("Error", errorViewModel));
            }

            DateTime nextMonday;
            int      todayInt = (int)DateTime.Today.DayOfWeek;

            if (todayInt == 0)
            {
                nextMonday = DateTime.Today.AddDays(1);
            }
            else
            {
                nextMonday = DateTime.Today.AddDays(8 - todayInt);
            }

            // Check if the order for this startdate can be editted
            if (nextMonday.Date != startDate.Date)
            {
                string         endDateString   = startDate.AddDays(6).ToString("d MMM", (new CultureInfo("nl-NL")).DateTimeFormat);
                string         startDateString = startDate.ToString("d MMM", (new CultureInfo("nl-NL")).DateTimeFormat);
                string         message         = "Bestelling voor periode " + startDateString + " - " + endDateString + " kan niet gewijzigd worden";
                ErrorViewModel errorViewModel  = new ErrorViewModel
                {
                    Message      = message,
                    ReturnAction = "Index"
                };

                return(View("Error", errorViewModel));
            }

            // Order can be editted / created
            Order Order = await GetOrderFromSession(startDate, customer.EMail);

            DetailedOrderViewModel detailedOrderViewModel =
                new DetailedOrderViewModel(Order);

            return(View(detailedOrderViewModel));
        }
示例#4
0
        public void Order_Price_Empty_Returns_Zero()
        {
            // Arrange
            Order order = new Order();
            DetailedOrderViewModel viewModel = new DetailedOrderViewModel(order);

            // Act
            decimal price = viewModel.CalculateTotalPrice();

            // Assert
            Assert.Equal((decimal)0.0, price);
        }