Ejemplo n.º 1
0
 public IActionResult PostRent([FromBody] Hire rent)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     _service.AddHire(rent);
     return CreatedAtAction("GetRent", new { id = rent.Id }, rent);
 }
Ejemplo 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"));
            }
        }