Пример #1
0
        public List <BikeItems> GetTypeBike(OrderBike ordersBike)
        {
            List <BikeItems> list = new List <BikeItems>();
            int flag = 1;

            do
            {
                var types = context.Type.ToList();
                foreach (var t in types)
                {
                    Console.WriteLine("TypeBike --{0}", t.Name);
                }
                Console.WriteLine("\n ");
                Console.WriteLine("Wybierz type bike");
                var typename  = Console.ReadLine();                                             //
                var freebykes = context.Bike.AsNoTracking().Where(b => b.Type.Name == typename) //sprawdzamy, czy mamy Bike w bazie
                                .Where(b => b.IsActive == true).ToList();
                if (freebykes.Count == 0)
                {
                    Console.WriteLine("");
                    Console.WriteLine($"Biks type {typename} net v nalichii!  Vvedite 1 vybrat  drugoj type.");
                    Console.WriteLine($"Ili  vvedite 0 esli ne podhodit");
                    flag = Convert.ToInt32(Console.ReadLine());
                    if (flag == 0)
                    {
                        return(list = null);
                    }
                }
                else
                {
                    foreach (var b in freebykes)
                    {
                        Console.WriteLine("Free Bike type  -- {0} number -- {1} ", b.Type.Name, b.BikeNumber);//
                    }
                    Console.WriteLine($"Podtverdite zakaz nabrav number ili 0 vyjti ");
                    var number = Console.ReadLine();
                    if (number == "0")
                    {
                        return(list = null);
                    }
                    else
                    {
                        var  type = context.Type.SingleOrDefault(t => t.Name == typename);
                        Bike bike = context.Bike.Where(b => b.Type.Name == type.Name)
                                    .Where(b => b.IsActive == true).Where(b => b.BikeNumber == number).Single();

                        var bikeItems = GetBikeItems(bike, ordersBike);
                        list.Add(bikeItems);
                        SaveIsActivate(bike.Id);
                    }
                }
                Console.WriteLine(new string('-', 45));
                Console.WriteLine("Vvedite 1 esli vybrat esce odin ili 0 vyjti ");
                flag = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine(new string('-', 45));
            } while (flag == 1);

            return(list);
        }
Пример #2
0
        }//zapisujemy wybrany bike pole isActivate(jesli wypozyczylismy bike, to piszemy, ze jest nieaktywny(false))

        public BikeItems GetBikeItems(Bike bike, OrderBike orderBike)
        {
            DateTime startrent = DateTime.Now;

            Console.WriteLine($" StartRent  Data {startrent}");
            Console.WriteLine("Wprowadz ilosc czasu wypozyczenia(Hours) ");
            int      hours      = Convert.ToInt32(Console.ReadLine());
            DateTime finishRent = startrent.AddHours(hours);
            Decimal  pricerent  = hours * bike.Price.Value;

            Console.WriteLine($" cena =============  {pricerent}");

            BikeItems bikeItems = new BikeItems//tworzymy obiekt BikeItems(zamowienie)
            {
                Bike       = bike,
                StartRent  = startrent,
                FinishRent = finishRent,
                OrderBike  = orderBike,
                Pledqe     = 200,
                PriceRent  = pricerent
            };

            return(bikeItems);
        }