Exemplo n.º 1
0
        public IActionResult HireCar()
        {
            HireCarViewModel hirevm = new HireCarViewModel();

            hirevm.Cars      = _service.GetCars(false);
            hirevm.Brands    = _service.GetBrands();
            hirevm.Customers = _service.GetCustomers();
            return(View(hirevm));
        }
Exemplo n.º 2
0
        public IActionResult Create([Bind("CarId,UserId")] HireCarViewModel postModel)
        {
            if (ModelState.IsValid && postModel.UserId.HasValue && postModel.CarId.HasValue)
            {
                Car car = _service.GetCardById(postModel.CarId);
                car.IsHired = true;
                Hire rent = new Hire();
                rent.HireDate       = DateTime.Now;
                rent.HiredCar       = _service.GetCardById(postModel.CarId);
                rent.HiringCustomer = _service.GetCustomerById(postModel.UserId);

                _service.UpdateCar(car);
                _service.AddHire(rent);
                return(RedirectToAction("ReturnCar"));
            }
            else
            {
                //TODO requierd message containing info validation fail
                return(RedirectToAction("HireCar"));
            }
        }