public ActionResult DeleteConfirmed(int id)
        {
            CarRentalModel carRentalModel = db.CarRentals.Find(id);

            db.CarRentals.Remove(carRentalModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public IActionResult AddCarRental([FromForm] CarRentalModel carRentalModel)
 {
     try
     {
         CarRentalModel addedCarRental = logic.AddCarRental(carRentalModel);
         return(Created("api/CarRental/" + addedCarRental.ID, addedCarRental));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
 public ActionResult Edit([Bind(Include = "CarRentalId,CustomerId,CarId,CarRentalDateFrom,CarRentalDateTo,CarRentalRate")] CarRentalModel carRentalModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(carRentalModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CarId      = new SelectList(db.Cars, "CarId", "Brand", carRentalModel.CarId);
     ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "CustomerName", carRentalModel.CustomerId);
     return(View(carRentalModel));
 }
        public ActionResult Create([Bind(Include = "CarRentalId,CustomerId,CarId,CarRentalDateFrom,CarRentalDateTo,CarRentalRate")] CarRentalModel carRentalModel)
        {
            if (ModelState.IsValid)
            {
                db.CarRentals.Add(carRentalModel);
                db.SaveChanges();
                //return RedirectToAction("Index");
                return(RedirectToAction("Index", "CustomerModels", "Index"));
            }

            ViewBag.CarId      = new SelectList(db.Cars, "CarId", "Brand", carRentalModel.CarId);
            ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "CustomerName", carRentalModel.CustomerId);
            return(View(carRentalModel));
        }
        // GET: CarRentalModels/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRentalModel carRentalModel = db.CarRentals.Find(id);

            if (carRentalModel == null)
            {
                return(HttpNotFound());
            }
            return(View(carRentalModel));
        }
        // GET: CarRentalModels/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRentalModel carRentalModel = db.CarRentals.Find(id);

            if (carRentalModel == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CarId      = new SelectList(db.Cars, "CarId", "Brand", carRentalModel.CarId);
            ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "CustomerName", carRentalModel.CustomerId);
            return(View(carRentalModel));
        }
Exemplo n.º 7
0
        public IActionResult GetOneCarRental(int id)
        {
            try
            {
                CarRentalModel carRental = logic.GetOneCarRental(id);

                if (carRental == null)
                {
                    return(NotFound($"id {id} not found"));
                }

                return(Ok(carRental));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemplo n.º 8
0
        public IActionResult UpdateFullCarRental(int id, [FromForm] CarRentalModel carRentalModel)
        {
            try
            {
                carRentalModel.ID = id;

                CarRentalModel updatedCarRental = logic.UpdateFullCarRental(carRentalModel);

                if (updatedCarRental == null)
                {
                    return(NotFound($"id {id} not found"));
                }

                return(Ok(updatedCarRental));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
        public ActionResult Create(int id)
        {
            // ViewBag.CarId = new SelectList(db.Cars, "CarId", "Brand" + "Model");

            ViewBag.CarId = new SelectList((from s in db.Cars.ToList()
                                            select new
            {
                CarId = s.CarId,
                CarData = s.Brand + " " + s.Model + " " + s.ProductionYear + " " + s.Colour
            }),
                                           "CarId",
                                           "CarData",
                                           null);


            CustomerModel customer = db.Customers.Single(a => a.CustomerId == id);

            CarRentalModel comm = new CarRentalModel();

            comm.CustomerId = id;
            return(View(comm));
        }