Exemplo n.º 1
0
 public CarRentalService()
 {
     repository      = new Repository();
     bookingMethods  = new BookingMethods(repository);
     carMethods      = new CarMethods(repository);
     customerMethods = new CustomerMethods(repository);
 }
Exemplo n.º 2
0
        public List <CarInfo> GetCarsByIds(CarRequest request)
        {
            if (request.LicenseKey != "Passcode")
            {
                throw new FaultException("Wrong License Key");
            }

            CarMethods carService = new CarMethods();

            var tempCarList = carService.GetById(request.CarIds);

            var carList = new List <Car>();

            foreach (Domain.Car c in tempCarList)
            {
                carList.Add(new Car
                {
                    Id    = c.Id,
                    Brand = c.Brand,
                    Model = c.Model,
                    Year  = c.Year,
                    RegNr = c.RegNr
                });
            }

            var carListResult = new List <CarInfo>();

            foreach (Car c in carList)
            {
                carListResult.Add(new CarInfo(c));
            }

            return(carListResult);
        }
        public RestService()
        {
            Repository repository = new Repository();

            bookingMethods  = new BookingMethods(repository);
            carMethods      = new CarMethods(repository);
            customerMethods = new CustomerMethods(repository);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var start = DateTime.Now.AddDays(6);
            var end   = DateTime.Now.AddDays(8);

            var carData = new CarMethods();
            var cars    = carData.GetAvailableCars(start, end);
        }
Exemplo n.º 5
0
        public void AddCar(CarInfo car)
        {
            var carService = new CarMethods();

            var newCar = new Domain.Car
            {
                Id    = car.Id,
                Brand = car.Brand,
                Model = car.Model,
                Year  = car.Year,
                RegNr = car.RegNr
            };

            carService.Add(newCar);
        }
        public List <Car> GetAllCars()
        {
            CarMethods carService = new CarMethods();

            var carList    = carService.GetAllCars();
            var newCarList = new List <Car>();

            foreach (Domain.Car c in carList)
            {
                newCarList.Add(new Car
                {
                    Id    = c.Id,
                    Brand = c.Brand,
                    Model = c.Model,
                    Year  = c.Year,
                    RegNr = c.RegNr
                });
            }

            return(newCarList);
        }
Exemplo n.º 7
0
        public void RemoveCar(string RegNr)
        {
            var carService = new CarMethods();

            carService.Remove(RegNr);
        }
        public List <int> GetAvailableCarsByDates(DateTime fromDate, DateTime toDate)
        {
            CarMethods carService = new CarMethods();

            return(carService.GetAllAvailable(fromDate, toDate));
        }
        static void Main(string[] args)
        {
            //var api = new CustomerMethods();

            CarMethods.Add(new Car {
                Model = "Diablo", Brand = "Lamborgini", ManufacturingYear = 1993, RegistrationNo = "GLO892"
            });
            CarMethods.Add(new Car {
                Model = "Gallardo", Brand = "Lamborgini", ManufacturingYear = 2013, RegistrationNo = "JLO112"
            });
            CustomerMethods.Add(new Customer {
                FirstName = "Bert", LastName = "Karlsson", Email = "*****@*****.**", PhoneNumber = "6666666"
            });
            BookingMethods.Add(new Booking
            {
                CustomerId = 1,
                StartTime  = new DateTime(2018, 10, 25, 09, 00, 00),
                EndTime    = new DateTime(2019, 01, 01, 09, 00, 00),
                BookingCar = new Car {
                    Id = 1
                }
            });
            CarMethods.PickUp(1);

            //Console.WriteLine("Car rental:");

            //DateTime startDate = new DateTime(2018, 10, 25);
            //DateTime endDate = new DateTime(2019, 01, 20);

            //List<Car> availableCars = api.ListAvailableCars(startDate, endDate);

            //Console.WriteLine("Available cars (" + startDate + " to " + endDate + "):");
            //foreach (Car car in availableCars)
            //{
            //    Console.WriteLine(car.Brand + " " + car.Model);
            //}

            //var repo = new Repository();

            //    var customers = repo.DataSet<Customer>().ToList();
            //    var cars = repo.DataSet<Car>().ToList();
            //    var bookings = repo.DataSet<Booking>().ToList();


            //    repo.AddRange(new[] {
            //        new Customer
            //    {
            //        FirstName = "Pelle",
            //        LastName = "Kanin",
            //        Email = "*****@*****.**",
            //        PhoneNumber = "123123123",
            //    },
            //        new Customer
            //    {
            //        FirstName = "Gert",
            //        LastName = "Bert",
            //        Email = "*****@*****.**",
            //        PhoneNumber = "999123123",
            //    }
            //    });
            //    repo.AddRange(new[] {
            //    new Car{
            //        RegistrationNo = "ABC123",
            //        Brand = "Volvo",
            //        ManufacturingYear = 2018,
            //        Model ="V90"
            //    },
            //    new Car {
            //        RegistrationNo = "DEF456",
            //        Brand = "Volkswagen",
            //        ManufacturingYear = 2018,
            //        Model ="Passat"
            //    }
            //    }
            //    );
            //    repo.SaveChanges();

            //    repo.Add(new Booking
            //    {
            //        CustomerId = repo.DataSet<Customer>().Where(c => c.FirstName == "Pelle").Select(c => c.Id).Single(),
            //        StartTime = new DateTime(2018, 11, 01),
            //        EndTime = new DateTime(2018, 11, 03),

            //        //BookingCars = new Booking = repo.DataSet<Car>().Where(c => c.RegistrationNo == "ABC123").ToList();
            //    });
            //    repo.SaveChanges();
            //    var booking = repo.DataSet<Booking>().Where(b => b.BookingCustomer.FirstName == "Pelle").FirstOrDefault();

            //    booking.BookingCars = new[] {
            //        new BookingCar
            //        {
            //            Booking = booking,
            //            Car = repo.DataSet<Car>().Single(c => c.RegistrationNo == "ABC123")
            //        }
            //    };

            //    repo.SaveChanges();


            //customers = repo.DataSet<Customer>().ToList();
            //cars = repo.DataSet<Car>().ToList();
            //bookings = repo.DataSet<Booking>().ToList();

            //var bookingFirstName = repo.DataSet<Booking>().Where(b => b.Id == 1).Select(b => b.BookingCustomer.FirstName).Single().ToString();
            //var startDate = new DateTime(2018, 10, 25);
            //var endDate = new DateTime(2019, 01, 20);

            //CarRentalContext context = new CarRentalContext();

            //List<Booking> bookings = repo.Context.Bookings
            //    .Include(b => b.BookingCars)
            //    .ThenInclude(bc => bc.Car)
            //    .Where(b => (b.StartTime < endDate && b.EndTime > startDate)).ToList();

            //Console.WriteLine("Not available cars (" + startDate.ToString() + " to " + endDate.ToString() + "):");
            //foreach (Booking booking in bookings)
            //{
            //    foreach(BookingCar car in booking.BookingCars)
            //    {
            //        Console.WriteLine(car.Car.Brand + " " + car.Car.Model);
            //    }
            //}

            //var book = repo.DataSet<Booking>().Where(b => b.Id == 2).Single();

            //repo.Remove(book);
            //repo.SaveChanges();

            // var cust = repo.DataSet<Customer>().ToList();

            //.Where(b=>!(b.Booking.StartTime < endDate && b.Booking.EndTime > startDate))

            Console.ReadLine();
        }