Esempio n. 1
0
        public static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder
            .RegisterGeneric(typeof(Repository <>))
            .As(typeof(IRepository <>))
            .SingleInstance();

            containerBuilder
            .RegisterType <BikeNameVerifier>()
            .As <IBikeNameVerifier>();

            containerBuilder
            .RegisterType <BikeService>()
            .As <IBikeService>();

            containerBuilder
            .RegisterType <RentPointService>()
            .As <IRentPointService>();

            containerBuilder
            .RegisterType <EmployeeService>()
            .As <IEmployeeService>();

            containerBuilder
            .RegisterType <RentService>()
            .As <IRentService>();

            containerBuilder
            .RegisterType <DepositCalculator>()
            .As <IDepositCalculator>();

            containerBuilder
            .RegisterType <RentSumCalculate>()
            .As <IRentSumCalculate>();

            containerBuilder
            .RegisterType <ReserveService>()
            .As <IReserveService>();

            containerBuilder.RegisterAssemblyTypes(typeof(RentPointCriterion).GetTypeInfo().Assembly).AsClosedTypesOf(typeof(IQuery <,>));
            containerBuilder.RegisterGeneric(typeof(QueryFor <>)).As(typeof(IQueryFor <>));
            containerBuilder.RegisterTypedFactory <IQueryBuilder>().InstancePerLifetimeScope();
            containerBuilder.RegisterTypedFactory <IQueryFactory>().InstancePerLifetimeScope();

            containerBuilder.RegisterAssemblyTypes(typeof(AddRentPointCommand).GetTypeInfo().Assembly).AsClosedTypesOf(typeof(ICommand <>));
            containerBuilder.RegisterType <CommandBuilder>().As <ICommandBuilder>().InstancePerLifetimeScope();
            containerBuilder.RegisterTypedFactory <ICommandFactory>().InstancePerLifetimeScope();

            containerBuilder.RegisterType <App>();

            IContainer container = containerBuilder.Build();



            App app = container.Resolve <App>();

            Employee  myEmployee  = app.CreateEmployee("Nya", "Nyan", "Nyanyan");
            RentPoint myRentPoint = app.AddRentPoint("rp1", "adress1", myEmployee);

            Employee  otherEmployee  = app.CreateEmployee("otherNya", "otherNyan", "otherNyanyan");
            RentPoint otherRentPoint = app.AddRentPoint("rp2", "adress2", otherEmployee);

            Client client = app.CreateClient("Keke", "Ke", "Kekekeke");
            Client clientWhoWantTakeReservedBike = app.CreateClient("aaa", "a", "aaaaa");

            Deposit deposit = new MoneyDeposit(5000);


            app.AddBike("Кама", 50, 4500, myRentPoint);
            app.AddBike("Rainbow Dash", 50, 5000, myRentPoint);
            app.AddBike("Rainbow Crash", 60, 4700, myRentPoint);
            //app.AddBike("Кама", 100, myRentPoint);

            Bike iChooseThisBike = app.GetBikes().FirstOrDefault(x => x.Name == "Кама");


            app.ReserveBike(client, iChooseThisBike, DateTime.UtcNow.AddDays(1));

            //app.GetBikeInRent(client, iChooseThisBike, deposit);

            bool iBrokeBike = true;

            app.GetBikeInRent(client, iChooseThisBike, deposit);
            app.ReturnBike(iChooseThisBike, otherRentPoint, iBrokeBike);

            app.GetRentPoints();

            app.GetAllFreeBikesOnRentPoint(myRentPoint);

            Bike likeItBike = app.GetBikes().FirstOrDefault(x => x.Name == "Rainbow Dash");

            app.ReserveBike(client, likeItBike, DateTime.UtcNow.AddDays(1));

            app.GetOpenReserveByBike(likeItBike);

            app.GetBikes();
            Console.ReadLine();

            container.Dispose();
        }
        static void Main(string[] args)
        {
            //// string metinsel veri tipi
            //string hi = "hello world!2";
            //var hi2 = "hello bursa";
            //decimal sayi = 5;
            //decimal sayi2 = 2;
            //double bolum = (double)(sayi / sayi2);
            //Console.WriteLine(bolum);


            // deger atama ile klasik yolla olusturuldu
            Bike bike = new Bike();

            bike.Brand     = "Yamaha";
            bike.ModelName = "RZ255";
            bike.Tires     = 2;
            bike.Price     = 12.39;
            bike.HasBasket = true;

            // constructor method ile olusturuldu
            Car car = new Car("Fiat", "Punto", 4, 500.55, false);

            // scope ile kisayolla olusturuldu
            Car car2 = new Car
            {
                Brand      = "Honda",
                ModelName  = "Civic",
                Price      = 909.13,
                Tires      = 4,
                HasSunroof = true
            };
            Bike bike2 = new Bike("Honda", "AZ7899", 50.33, true);

            string sunroofDurumu = "";

            if (car.HasSunroof == true)
            {
                sunroofDurumu = "Var";
            }
            else
            {
                sunroofDurumu = "Yok";
            }
            Console.WriteLine("Araba");
            Console.WriteLine("Marka: " + car.Brand);
            Console.WriteLine("Model: " + car.ModelName);
            Console.WriteLine("Teker Sayisi: " + car.Tires);
            Console.WriteLine("Fiyat: " + car.Price);
            Console.WriteLine("Sunroof Var mi? " + sunroofDurumu
                              );
            Console.WriteLine("---");

            Console.WriteLine("Araba");
            Console.WriteLine("Marka: " + car2.Brand);
            Console.WriteLine("Model: " + car2.ModelName);
            Console.WriteLine("Teker Sayisi: " + car2.Tires);
            Console.WriteLine("Fiyat: " + car2.Price);
            Console.WriteLine("Sunroof Var mi? " + sunroofDurumu
                              );
            Console.WriteLine("---");

            Console.WriteLine("Motorsiklet");
            Console.WriteLine("Marka: " + bike.Brand);
            Console.WriteLine("Model: " + bike.ModelName);
            Console.WriteLine("Teker Sayisi: " + bike.Tires);
            Console.WriteLine("Fiyat: " + bike.Price);
            Console.WriteLine("Sepet Var mi? " +
                              (bike.HasBasket ? "Var" : "Yok"));

            Console.WriteLine("---");

            Console.WriteLine("Motorsiklet2");
            Console.WriteLine("Marka: " + bike2.Brand);
            Console.WriteLine("Model: " + bike2.ModelName);
            Console.WriteLine("Teker Sayisi: " + bike2.Tires);
            Console.WriteLine("Fiyat: " + bike2.Price);
            Console.WriteLine("Sepet Var mi? " +
                              (bike2.HasBasket ? "Var" : "Yok"));

            Console.ReadLine();
        }