// GET: Rents/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var user = HttpContext.User.Identity.Name;
            var cars = await _context.Cars
                       .SingleOrDefaultAsync(m => m.IdCar == id);

            if (cars == null)
            {
                return(NotFound());
            }
            cars.Available = false;
            Rent s = new Rent {
                Login = user, IdCar = id
            };

            _context.Update(cars);
            await _context.SaveChangesAsync();

            _context.Add(s);
            await _context.SaveChangesAsync();

            var cars2 = await _context.Cars
                        .SingleOrDefaultAsync(m => m.IdCar == id);

            return(View(cars2));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("IdCar,Mark,Model,Category,Available")] Cars cars)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cars);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cars));
        }
        public async Task <IActionResult> Create([Bind("Id,CarRegNo,CarMake,CarModel,Year,ImageUrl,PricePerDay")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Create([Bind("Id,UserName")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Beispiel #5
0
        public async Task <IActionResult> Create([Bind("Id,DriverName,CarId")] Driver driver)
        {
            if (ModelState.IsValid)
            {
                _context.Add(driver);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarId"] = new SelectList(_context.Car, "Id", "Id", driver.CarId);
            return(View(driver));
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("BookingId,CarId,UserId,NumberOfDays")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarId"]  = new SelectList(_context.Set <Car>(), "Id", "Id", booking.CarId);
            ViewData["UserId"] = new SelectList(_context.Set <User>(), "Id", "Id", booking.UserId);
            return(View(booking));
        }