Beispiel #1
0
        public async Task <IActionResult> PutGarage(int id, Garage garage)
        {
            if (id != garage.GarageId)
            {
                return(BadRequest());
            }

            _context.Entry(garage).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GarageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        /// <summary>
        /// Precondition: The given reservation must exist in the database
        /// Activates the given reservation. This means the car has been rented to a customer.
        /// A car is assigned and the car mileage is tracked.
        /// </summary>
        /// <param name="reservationId"></param>
        /// <returns>Returns the ActivatedReservation class that was created.</returns>
        ///

        public async Task <ActivatedReservation> activateReservation(int reservationId)
        {
            RentalCar car = await db.getAvailableRentalCar(reservationId);

            var res = await db.getReservation(reservationId);

            if (res.cancelled)
            {
                throw new InvalidOperationException("A cancelled reservation cannot be activated.");
            }

            ActivatedReservation activatedReservation = new ActivatedReservation(res, car, car.currentMileage, true);

            if (activatedReservation.reservation.expectedReturnDate < DateTime.Now ||
                activatedReservation.reservation.rentalDate > DateTime.Now)
            {
                throw new InvalidOperationException("The rental date has not yet been passed. " +
                                                    "Cannot activate reservation. " +
                                                    "\nGiven startDate: " + activatedReservation.reservation.rentalDate +
                                                    "\nGiven endDate: " + activatedReservation.reservation.rentalDate);
            }

            context.activatedReservations.Add(activatedReservation);
            await context.SaveChangesAsync();

            return(activatedReservation);
        }
        public async Task <IActionResult> PutClient(int id, Client client)
        {
            if (id != client.Id)
            {
                return(BadRequest());
            }

            _context.Entry(client).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #4
0
        public async Task <string> CreateAsync(BookingStart model)
        {
            var bookingId = await GenerateBookingNumberAsync();

            var customer = new Customer
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Ssn       = model.SSN
            };

            await context.Customer.AddAsync(customer);

            var booking = new Booking
            {
                BookingId    = bookingId,
                StartDate    = model.StartDate,
                CustomerId   = customer.Id,
                CarId        = model.Car.Value,
                CarLicense   = model.License,
                StartMileage = model.StartMileage.Value,
            };

            await context.Booking.AddAsync(booking);

            await context.SaveChangesAsync();

            return(bookingId);
        }
        public async Task <int> AddAsync(Car car)
        {
            await _context.Cars.AddAsync(car);

            await _context.SaveChangesAsync();

            return(car.Id);
        }
        public async Task <int> AddAsync(CarBrand carBrand)
        {
            await _context.CarBrands.AddAsync(carBrand);

            await _context.SaveChangesAsync();

            return(carBrand.Id);
        }
        public async Task <int> AddAsync(CarType carType)
        {
            await _context.CarTypes.AddAsync(carType);

            await _context.SaveChangesAsync();

            return(carType.Id);
        }
Beispiel #8
0
        public async Task <T> Remove(T entity)
        {
            // var item = _context.Set<T>().Find(id);

            _context.Set <T>().Remove(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
        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));
        }
Beispiel #10
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));
        }
Beispiel #11
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));
        }
Beispiel #12
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));
        }
Beispiel #14
0
        public async Task <ReservationDetailDTO> RentCar(Reservation reservation)
        {
            if (!await CheckCarAvailability(reservation.CarId, reservation.PickUpDate, reservation.ReturnDate))
            {
                throw new ArgumentException("Selected Car is not available at this time");
            }
            _context.Reservations.Add(reservation);
            await _context.SaveChangesAsync();

            return(await ReservationToDTO(reservation));
        }
        // --------------------------------
        // DATABASE WRITE
        // --------------------------------

        public async Task setBaseDayRentalPrice(double baseDayRentalPrice)
        {
            var currentBaseDayRentalPriceConfig = await(from c in context.configItems
                                                        where c.configName == "baseDayRentalPrice"
                                                        select c).SingleOrDefaultAsync();

            // If baseDayRentalPrice does not exist in config, create it and assign given value
            if (currentBaseDayRentalPriceConfig == null)
            {
                currentBaseDayRentalPriceConfig = new ConfigItem {
                    configName = "baseDayRentalPrice", value = baseDayRentalPrice.ToString()
                };
                context.configItems.Add(currentBaseDayRentalPriceConfig);
            }

            currentBaseDayRentalPriceConfig.value = baseDayRentalPrice.ToString();
            await context.SaveChangesAsync();
        }
Beispiel #16
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("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));
        }
Beispiel #18
0
        public async Task <bool> Create(Booking entity)
        {
            var car = await _context.Cars.FirstOrDefaultAsync <Car>(x => x.Id == entity.Car.Id);

            var customer = await _context.Customers.FirstOrDefaultAsync(x => x.IdentityNumber == entity.Customer.IdentityNumber);

            if (car?.Status == Status.Available)
            {
                if (customer == null)
                {
                    _context.Customers.Add(new Customer {
                        IdentityNumber = entity.Customer.IdentityNumber
                    });
                    await _context.SaveChangesAsync();

                    customer = await _context.Customers.AsNoTracking().FirstOrDefaultAsync(x => x.IdentityNumber == entity.Customer.IdentityNumber);
                }
                entity.Customer = customer;
                _context.Bookings.Add(entity);
                car.Status = Status.Unavailable;
            }
            return(await _context.SaveChangesAsync() > 0);
        }
        public async Task RentCarAsync(int carId)
        {
            Car car = await _context.Cars.FindAsync(carId);

            if (car == null)
            {
                throw new Exception("Car not found");
            }

            RentalTransaction rt = new RentalTransaction()
            {
                Id           = 0,
                CarId        = carId,
                DateRented   = DateTime.Now,
                DateReturned = null
            };
            await _context.RentalTransactions.AddAsync(rt);

            await _context.SaveChangesAsync();

            car.IsAvailable = false;
            car.CurrentRentalTransactionId = rt.Id;
            await _context.SaveChangesAsync();
        }
Beispiel #20
0
        public async Task <Car> AddCar(AddCarCommand addCarCommand)
        {
            Car car = new Car
            {
                Manufacture   = addCarCommand.Manufacture,
                Model         = addCarCommand.Model,
                Year          = addCarCommand.Year,
                Vin           = addCarCommand.Vin,
                Description   = addCarCommand.Description,
                IsAvailable   = addCarCommand.IsAvailable,
                CarGroupId    = addCarCommand.CarGroupId,
                Observation   = addCarCommand.Observation,
                StandardPrice = addCarCommand.StandardPrice,
                DateCreated   = addCarCommand.DateCreated,
                CreatedBy     = addCarCommand.CreatedBy
            };
            await _dbContext.AddAsync(car);

            await _dbContext.SaveChangesAsync();

            return(car);
        }
 public async Task <bool> Create(Registration entity)
 {
     _context.Registrations.Add(entity);
     return(await _context.SaveChangesAsync() > 0);
 }
Beispiel #22
0
 public async Task <bool> Create(Car entity)
 {
     _context.Cars.Add(entity);
     return(await _context.SaveChangesAsync() > 0);
 }
Beispiel #23
0
 public async Task <int> CommitAsync()
 {
     return(await _dbContext.SaveChangesAsync());
 }
Beispiel #24
0
 public async Task SaveAsync()
 {
     await _context.SaveChangesAsync();
 }