示例#1
0
        internal OrdersReceiptVM ReturnOrder(OrdersReturnVM viewModel)
        {
            Orders order = ordersRepository.GetOrderById(viewModel.OrderNumber);

            if (order.ReturnDate < viewModel.Date)
            {
                order.ReturnDate = viewModel.Date;
            }
            order.CarReturned          = true;
            order.KilometerAfterRental = viewModel.Kilometre;


            int membershipLevel = customersService.GetMembershipLevelByID(order.CustomerId);
            var carType         = carsService.GetCarTypeByID(order.CarId);
            var KMDriven        = (order.KilometerAfterRental - order.KilometerBeforeRental);

            order.Cost = CalcRentalPrice(carType, order.KilometerAfterRental, order.KilometerBeforeRental, order.ReturnDate, order.RentalDate, membershipLevel);

            ordersRepository.Update(order);
            eventsService.CreateReturnOrderEvent(order);
            customersService.UpdateMembershipLevel(order.Customer, KMDriven);
            carsService.UpdateCarKMByID(order.CarId, order.KilometerAfterRental);

            return(new OrdersReceiptVM
            {
                CarReturned = true,
                ReturnDate = viewModel.Date,
                KilometerAfterRental = viewModel.Kilometre,
                Id = viewModel.OrderNumber,
                KilometerBeforeRental = order.KilometerBeforeRental,
                RentalDate = order.RentalDate,
                rentalPrice = order.Cost
            });
        }
示例#2
0
        public IActionResult Return(OrdersReturnVM viewModel)
        {
            viewModel.KilometerBeforeRental = ordersService.GetKmByID(viewModel.OrderNumber);

            if (viewModel.Kilometre < viewModel.KilometerBeforeRental)
            {
                return(Content("Bilen kan inte lämnas tillbaka med en mätarställning som är lägre än vid hyrning"));
            }
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            OrdersReceiptVM or = ordersService.ReturnOrder(viewModel);

            return(RedirectToAction("receipt", "Orders", or));
        }