Example #1
0
        public async Task <IActionResult> Create(string plate, int customerid, DateTime startdate, DateTime enddate, string location, string couponcode, Reservation reservation)
        {
            if (_context.Cars.Where(c => c.Plate == plate && c.Location == location).FirstOrDefault() != null)
            {
                Car MyCar = _context.Cars.Where(c => c.Plate == plate && c.Location == location).FirstOrDefault();
                reservation.CarId    = MyCar.CarId;
                reservation.Plate    = MyCar.Plate;
                reservation.Location = MyCar.Location;
                if (_context.Customers.Where(c => c.CustomerId == customerid).FirstOrDefault() != null)
                {
                    Customer MyCustomer = _context.Customers.Where(c => c.CustomerId == customerid).FirstOrDefault();
                    reservation.CustomerId = MyCustomer.CustomerId;
                    reservation.StartDate  = startdate;
                    reservation.EndDate    = enddate;
                    if ((reservation.StartDate <= reservation.EndDate) && (reservation.StartDate >= DateTime.Now))
                    {
                        if (_context.Reservations.Where(c => (c.EndDate < reservation.StartDate || c.StartDate > reservation.EndDate)).Any())
                        {
                            _context.Add(reservation);
                            await _context.SaveChangesAsync();

                            return(RedirectToAction(nameof(Index)));
                        }
                        else if (_context.Reservations.Where(c => c.Plate == reservation.Plate).Any() == false)
                        {
                            _context.Add(reservation);
                            await _context.SaveChangesAsync();

                            return(RedirectToAction(nameof(Index)));
                        }
                    }
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(View());
            }
            return(View());
        }
        public async Task <IActionResult> Create([Bind("CustomerId,Name,BirthDate,Location")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("CarId,Plate,Manufacturer,Model,PricePerDay,Location")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("CouponCode,Description,Discount")] Coupon coupon)
        {
            if (ModelState.IsValid)
            {
                _context.Add(coupon);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(coupon));
        }
        public async Task <IActionResult> Create([Bind("ReservStatsID,Name,Description")] ReservationStatus reservationStatus)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reservationStatus);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reservationStatus));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("Id,Brand,Model,Year,Mileage,Fuel,Seats,combisudan,about,ImgSrc")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Example #7
0
        protected string CreateAndSaveACarRental(string carCategory, string customerSocialSecurityNumber, decimal currentMilage)
        {
            using (var db = new CarRentalContext())
            {
                var rental = new CarRental()
                {
                    CarCategory = carCategory,
                    CustomerSocialSecurityNumber = customerSocialSecurityNumber,
                    CarMilageAtRentInKm          = currentMilage,
                    Rented = _dateTimeProvider.GetUtcNow()
                };
                db.Add(rental);
                db.SaveChanges();

                rental.BookingNumber = "BN" + rental.Id; //No real req. here, just it made up for now
                db.SaveChanges();

                return(rental.BookingNumber);
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Rentee,CarId,Car,From,To")] Rental rental)
        {
            if (ModelState.IsValid)
            {
                var cars = await _context.Cars.ToListAsync();

                Car car = cars.SingleOrDefault(car => car.Id == rental.CarId);

                if (car == null)
                {
                    return(NotFound());
                }

                rental.Car = car.Brand + " " + car.Model;

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rental));
        }