예제 #1
0
        public CarBrand DeleteCarBrand(int id)
        {
            var carBrand = _context.CarBrands.Find(id);

            if (carBrand == null)
            {
                return(null);
            }

            _context.CarBrands.Remove(carBrand);
            _context.SaveChanges();

            return(carBrand);
        }
예제 #2
0
        public CarClass DeleteCarClass(int id)
        {
            var carClass = _context.CarClasses.Find(id);

            if (carClass == null)
            {
                return(null);
            }

            _context.CarClasses.Remove(carClass);
            _context.SaveChanges();

            return(carClass);
        }
예제 #3
0
        public async Task <ActionResult <Contract> > PostContract(Contract contract)
        {
            if (!ContractExists(contract.ReservationId))
            {
                Reservation reservation = new Reservation();
                reservation       = _context.Reservations.Find(contract.ReservationId);
                reservation.State = ReservationState.contracted;
                _context.Reservations.Update(reservation);
                _context.SaveChanges();
                _context.Contracts.Add(contract);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetContract", new { id = contract.Id }, contract));
            }

            return(NoContent());
        }
예제 #4
0
 public void Add(Car car)
 {
     _dbContext.Add(car);
     _dbContext.SaveChanges();
 }
예제 #5
0
 public void Add(Reservation reservation)
 {
     _dbContext.Reservations.Add(reservation);
     _dbContext.SaveChanges();
 }
예제 #6
0
 public void Add(Customer customer)
 {
     _dbContext.Customers.Add(customer);
     _dbContext.SaveChanges();
 }
예제 #7
0
        public static void InitTestData(CarRentDBContext context)
        {
            var carclasslist = new List <CarClass>()
            {
                new CarClass()
                {
                    Class = "Economy", CostsPerDay = 25m
                },
                new CarClass()
                {
                    Class = "Middleclass", CostsPerDay = 40m
                },
                new CarClass()
                {
                    Class = "Luxury", CostsPerDay = 55m
                }
            };

            var cartypelist = new List <CarType>()
            {
                new CarType()
                {
                    carType = "Limousine"
                },
                new CarType()
                {
                    carType = "Kombi"
                },
                new CarType()
                {
                    carType = "SUV"
                }
            };

            var carbrandlist = new List <CarBrand>()
            {
                new CarBrand()
                {
                    BrandName = "VW"
                },
                new CarBrand()
                {
                    BrandName = "Audi"
                },
                new CarBrand()
                {
                    BrandName = "Fiat"
                },
                new CarBrand()
                {
                    BrandName = "Seat"
                }
            };

            context.CarClasses.AddRange(carclasslist);
            context.CarBrands.AddRange(carbrandlist);
            context.CarTypes.AddRange(cartypelist);
            context.SaveChanges();

            var carlist = new List <Car>()
            {
                new Car()
                {
                    BrandId = 1, ClassId = 1, horsepower = 100, kilometer = 150000, RegistrationYear = 2020, TypeId = 1
                },
                new Car()
                {
                    BrandId = 2, ClassId = 2, horsepower = 150, kilometer = 150000, RegistrationYear = 2019, TypeId = 2
                },
                new Car()
                {
                    BrandId = 3, ClassId = 3, horsepower = 300, kilometer = 150000, RegistrationYear = 2018, TypeId = 3
                }
            };

            context.Cars.AddRange(carlist);
            context.SaveChanges();

            var customerlist = new List <Customer>()
            {
                new Customer()
                {
                    Adress = "W. Wolfensbergerstr. 3, 9424 Rheineck", EMailAdress = "*****@*****.**", Firstname = "Adrian", Lastname = "Kaufmann", Telephonenumber = "0765655282"
                },
                new Customer()
                {
                    Adress = "W. Wolfensbergerstr. 5, 9424 Rheineck", EMailAdress = "*****@*****.**", Firstname = "Max", Lastname = "Mustermann", Telephonenumber = "0798888888"
                },
                new Customer()
                {
                    Adress = "W. Wolfensbergerstr. 7, 9424 Rheineck", EMailAdress = "*****@*****.**", Firstname = "Vreni", Lastname = "Musterfrau", Telephonenumber = "0774445566"
                },
            };

            context.Customers.AddRange(customerlist);
            context.SaveChanges();

            var reservation = new Reservation()
            {
                CarId = 1, CustomerId = 1, RentalDate = new DateTime(2020, 02, 11), ReservationDate = new DateTime(2020, 01, 01), RentalDays = 8, State = ReservationState.pending
            };
            var reservation2 = new Reservation()
            {
                CarId = 2, CustomerId = 2, RentalDate = new DateTime(2020, 02, 11), ReservationDate = new DateTime(2020, 01, 01), RentalDays = 8, State = ReservationState.pending
            };
            var car      = context.Cars.Find(reservation.CarId);
            var carclass = context.CarClasses.Find(car.ClassId);

            reservation.Costs = reservation.RentalDays * carclass.CostsPerDay;
            context.Reservations.Add(reservation);
            context.Reservations.Add(reservation2);
            context.SaveChanges();
        }