Пример #1
0
        public ActionResult CheckBooking(BookingViewModel bookVM)
        {
            DiscountViewModel discountVM = new DiscountViewModel();

            bookVM.Booking = dbBooking.GetBookings().Where(x => x.Id.Equals(bookVM.Booking.Id)).FirstOrDefault();
            var customer = bookVM.Customer;

            if (checkCustomer(bookVM))
            {
                dbCustomer.Add(bookVM.Customer);
                dbBooking.AddCustomerToOrder(bookVM.Customer.Id, bookVM.Booking.Id);
            }
            else
            {
                bookVM.Customer      = customer;
                ViewBag.ErrorMessage = "Alle velden moeten ingevuld zijn, behalve tussenvoegsel";
                return(View("CustomerBooking", bookVM));
            }

            decimal price = Price(bookVM);

            decimal discount = discountVM.TotalDiscount(bookVM);

            if (discount != 0)
            {
                price = price * ((100 - discount) / 100);
            }


            bookVM.Booking.Payment  = price;
            bookVM.Booking.Discount = discount;
            dbBooking.addPaymentToOrder(bookVM.Booking.Payment, bookVM.Booking.Id);
            dbBooking.AddDiscountToOrder(bookVM.Booking.Discount, bookVM.Booking.Id);

            return(View(bookVM));
        }