Inheritance: Listing
Beispiel #1
0
        public void AddMotorAndFillWithDetails(eTypeOfVeichle i_TypeOfVeichile, string i_LicenceID, string i_VehicleModel, float i_EngineCurrentEnergy, List <Tire> i_Tires, eLiecenceType i_LicenceType, int i_EngineCapacity)
        {
            switch (i_TypeOfVeichile)
            {
            case eTypeOfVeichle.FuelMotorCycle:
            case eTypeOfVeichle.ElectricMotorCycle:
                if (Vehicles == null)
                {
                    Vehicles = new List <Vehicle>();
                }

                if (Motors == null)
                {
                    Motors = new List <MotorBike>();
                }

                MotorBike motor = VeichileFactory.CreateMotorBike(i_TypeOfVeichile);
                motor.LicenceID            = i_LicenceID;
                motor.Model                = i_VehicleModel;
                motor.Engine.CurrentEnergy = i_EngineCurrentEnergy;
                motor.Tires                = i_Tires;
                motor.LiecenceType         = i_LicenceType;
                motor.EngineCapacity       = i_EngineCapacity;
                Motors.Add(motor);
                Vehicles.Add(motor);
                break;
            }
        }
        public IHttpActionResult PutMotorBike(int id, MotorBike motorBike)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != motorBike.Id)
            {
                return(BadRequest());
            }

            db.Entry(motorBike).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MotorBikeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public ActionResult RegMotor(UserCarMotorModel UCM)
        {
            // Create User reference
            string tempPW = Convert.ToBase64String(System.Security.Cryptography.SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(UCM.Password)));

            User user = new User
            {
                FirstName = UCM.FirstName,
                LastName  = UCM.LastName,
                UserName  = UCM.UserName,
                Password  = tempPW
            };

            // Create car reference
            MotorBike motorBike = new MotorBike
            {
                MotorReg   = UCM.MotorReg,
                MotorValue = UCM.MotorValue,
                ModeofUse  = UCM.ModeofUse.ToString()
            };

            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();

                motorBike.UserId = user.UserId;
                db.MotorBikes.Add(motorBike);
                db.SaveChanges();

                return(RedirectToAction("PleaseLogin", "User"));
            }

            return(View());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            MotorBike motorBike = db.MotorBikes.Find(id);

            db.MotorBikes.Remove(motorBike);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public void ElectricEngine_Set_Get(uint a)
        {
            ElectricEngine _suut = new ElectricEngine(a);
            MotorBike      _uut  = new MotorBike(_suut);

            Assert.That(_suut.CurThrottle = a, Is.EqualTo(a));
            _uut.RunAtHalfSpeed();
            Assert.That(_suut.CurThrottle, Is.EqualTo(a / 2));
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var bike = new MotorBike(new GasEngine(100));

            bike.RunAtHalfSpeed();

            bike = new MotorBike(new DieselEngine(30));
            bike.RunAtHalfSpeed();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            MotorBike myBike = new MotorBike(new GasEngine(100));

            myBike.SetSpeed(90);
            Console.WriteLine("Current speed is: " + myBike.CurrentSpeed().ToString());
            myBike.RunAtHalfSpeed();
            Console.WriteLine("Current speed is: " + myBike.CurrentSpeed().ToString());
            Console.ReadLine();
        }
 public ActionResult Edit([Bind(Include = "Id,MotorName,MakeYear,Company")] MotorBike motorBike)
 {
     if (ModelState.IsValid)
     {
         db.Entry(motorBike).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(motorBike));
 }
 public ActionResult Edit([Bind(Include = "ID,title,model,make,estimatedPrice,drivenInKms,documents,condition,")] MotorBike motorBike)
 {
     if (ModelState.IsValid)
     {
         db.Entry(motorBike).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(motorBike));
 }
        public ActionResult Create([Bind(Include = "Id,MotorName,MakeYear,Company")] MotorBike motorBike)
        {
            if (ModelState.IsValid)
            {
                db.MotorBikes.Add(motorBike);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(motorBike));
        }
Beispiel #11
0
        public IActionResult Post([FromBody] MotorBike value)
        {
            if (string.IsNullOrWhiteSpace(value.Name))
            {
                return(BadRequest("Name cannot be empty"));
            }

            value.Id = _bikes.Max(p => p.Id) + 1;
            _bikes.Add(value);
            return(Created($"/api/MotorBikeApi/{value.Id}", value));
        }
        public IHttpActionResult GetMotorBike(int id)
        {
            MotorBike motorBike = db.MotorBikes.Find(id);

            if (motorBike == null)
            {
                return(NotFound());
            }

            return(Ok(motorBike));
        }
        public IHttpActionResult PostMotorBike(MotorBike motorBike)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MotorBikes.Add(motorBike);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = motorBike.Id }, motorBike));
        }
Beispiel #14
0
        public IActionResult Delete(int id)
        {
            MotorBike MotorBike = _db.MotorBikes.Find(id);

            if (MotorBike == null)
            {
                return(NotFound());
            }

            _db.MotorBikes.Remove(MotorBike);
            _db.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
        static void Main(string[] args)
        {
            #region abstract example

            ////var vehicle = new Vehicle();
            Vehicle car  = new Car();
            Vehicle bike = new MotorBike();

            car.Gas();
            bike.Gas();

            car.SwitchGear();
            bike.SwitchGear();
            Console.WriteLine();
            #endregion

            #region override virtual new
            Singer bariton = new Bariton();
            bariton.Sing();

            Singer tenor = new Tenor();
            tenor.Sing();
            Console.WriteLine();

            #endregion

            #region avoid if else
            List <Employee> employees = new List <Employee> {
                new Developer(), new Tester(), new Manager(), new Developer()
            };
            foreach (var employee in employees)
            {
                var sallary = employee.GetSallary();
                if (employee is Tester)
                {
                    sallary *= 1.5;
                }
                else if (employee is Developer)
                {
                    sallary *= 2;
                }
                else if (employee is Manager)
                {
                    sallary *= 10;
                }
                Console.WriteLine("{0} sallary: {1}", employee.ToString(), sallary);
            }
            Console.WriteLine();

            #endregion
        }
 private void ButSave_Click(object sender, EventArgs e)
 {
     if (receivedMotorBike == null)
     {
         MotorBike motorBike = new MotorBike();
         EditMotorBike(motorBike);
         FMenu.AddTransport(motorBike);
     }
     else
     {
         EditMotorBike(receivedMotorBike);
     }
     Close();
 }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MotorBike motorBike = db.MotorBikes.Find(id);

            if (motorBike == null)
            {
                return(HttpNotFound());
            }
            return(View(motorBike));
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("::::::::GasEngine::::::::");
            IEngine myGasEngine = new GasEngine(10);
            MotorBike myGasBike = new MotorBike(myGasEngine);
            System.Console.WriteLine("Run at half speed.");
            myGasBike.RunAtHalfSpeed();

            System.Console.WriteLine("::::::::DieselEngine:::::");
            IEngine myDieEngine = new DieselEngine(20);
            MotorBike myDieselBike = new MotorBike(myDieEngine);
            System.Console.WriteLine("Run at half speed.");
            myDieselBike.RunAtHalfSpeed();
        }
        static void Main(string[] args)
        {
            // NO NO can't have instances of an abstract class or interface
            //AutoMobile auto = new AutoMobile();

            Console.WriteLine("car c");
            Car c = new Car(true);

            c.SteerLeft();

            Console.WriteLine("car car");
            Car car = new Car();

            Console.WriteLine(car.IsOn);
            car.Start();
            car.SteerLeft();
            Console.WriteLine(car.IsOn);

            // with private set doesn't work
            //car.IsOn = false;

            car.Stop();
            Console.WriteLine(car.IsOn);

            Console.WriteLine("motorbike moto");
            MotorBike moto = new MotorBike();

            moto.Start();
            moto.SteerLeft();
            Console.WriteLine(moto.IsOn);

            Console.WriteLine("motorbike moto2");
            MotorBike moto2 = new MotorBike(true);

            Console.WriteLine(moto2.IsOn);
            moto2.SteerLeft();
            moto2.Stop();
            Console.WriteLine(moto2.IsOn);

            Console.ReadLine();


            Console.WriteLine("-----------");
            Boat boat = new Boat();

            boat.Steer(true);
            boat.Steer(true);
            boat.Steer(false);
            Console.WriteLine(boat.Steers);
        }
        public IHttpActionResult DeleteMotorBike(int id)
        {
            MotorBike motorBike = db.MotorBikes.Find(id);

            if (motorBike == null)
            {
                return(NotFound());
            }

            db.MotorBikes.Remove(motorBike);
            db.SaveChanges();

            return(Ok(motorBike));
        }
 public void SetMotorBike(MotorBike motorBike)
 {
     receivedMotorBike = motorBike;
     SetName(motorBike.Name);
     SetMaxSpeed(motorBike.MaxSpeed);
     SetWeight(motorBike.Weight);
     SetYear(motorBike.Year);
     SetNumOfWheels(motorBike.NumOfWheels);
     SetSideCar(motorBike.SideCar);
     SetPower(motorBike.EngineInfo.Power);
     SetVolume(motorBike.EngineInfo.Volume);
     SetTypeFuel(motorBike.EngineInfo.TypeFuel);
     SetNumGears(motorBike.TransmissionInfo.NumGears);
     SetTypeTransmission(motorBike.TransmissionInfo.TypeTransmission);
 }
        private void EditMotorBike(MotorBike motorBike)
        {
            motorBike.Name        = GetName();
            motorBike.MaxSpeed    = GetMaxSpeed();
            motorBike.Weight      = GetWeight();
            motorBike.Year        = GetYear();
            motorBike.NumOfWheels = GetNumOfWheels();
            motorBike.SideCar     = GetSideCar();
            Engine engine = new Engine(GetPower(), GetVolume(), GetTypeFuel());

            motorBike.EngineInfo = engine;
            Transmission transmission = new Transmission(GetNumGears(), GetTypeTransmission());

            motorBike.TransmissionInfo = transmission;
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            // ************************************** //
            // *** Gas engine and gas-driven bike *** //
            // ************************************** //
            var myGasEngine    = new GasEngine(100);
            var myGasMotorBike = new MotorBike(myGasEngine);
            var thr            = myGasEngine.CurThrottle;

            Console.WriteLine($"My gas throttle when idling is: {thr}.");
            thr = myGasEngine.MaxThrottle;
            Console.WriteLine($"My gas throttle at full speed is: {thr}");
            myGasMotorBike.RunAtHalfSpeed();
            thr = myGasEngine.CurThrottle;
            Console.WriteLine($"My gas throttle at half speed is: {thr}");

            // ******************************************** //
            // *** Diesel engine and diesel-driven bike *** //
            // ******************************************** //
            var myDieselEngine    = new DieselEngine(120);
            var myDieselMotorBike = new MotorBike(myDieselEngine);
            // Diesel-bike outputs:
            var thr2 = myDieselEngine.CurThrottle;

            Console.WriteLine($"My diesel throttle when idling is: {thr2}");
            thr2 = myDieselEngine.MaxThrottle;
            Console.WriteLine($"My diesel throttle at full speed is: {thr2}");
            myDieselMotorBike.RunAtHalfSpeed();
            thr2 = myDieselEngine.CurThrottle;
            Console.WriteLine($"My diesel throttle at half speed is: {thr2}");

            // ************************************************ //
            // *** Electric engine and electric-driven bike *** //
            // ************************************************ //
            var myElectricEngine    = new ElectricEngine(168);
            var myElectricMotorBike = new MotorBike(myElectricEngine);
            // Electric-bike outputs:
            var thr3 = myElectricEngine.CurThrottle;

            Console.WriteLine($"My electric throttle when idling is: {thr3}");
            thr3 = myElectricEngine.MaxThrottle;
            Console.WriteLine($"My electric throttle at full speed is: {thr3}");
            myElectricMotorBike.RunAtHalfSpeed();
            thr3 = myElectricEngine.CurThrottle;
            Console.WriteLine($"My electric throttle at half speed is: {thr3}");

            Console.ReadLine();
        }
Beispiel #24
0
        public ActionResult NewRegMotor(CarMotorViewModel newCarMotor)
        {
            MotorBike newMoto = new MotorBike();

            newMoto.UserId     = (int)Session["UserId"];
            newMoto.MotorReg   = newCarMotor.MotorReg;
            newMoto.MotorValue = newCarMotor.MotorValue;
            newMoto.ModeofUse  = newCarMotor.ModeofUse.ToString();
            if (ModelState.IsValid)
            {
                db.MotorBikes.Add(newMoto);
                db.SaveChanges();
            }

            return(View());
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("::::::::GasEngine::::::::");
            IEngine   myGasEngine = new GasEngine(10);
            MotorBike myGasBike   = new MotorBike(myGasEngine);

            System.Console.WriteLine("Run at half speed.");
            myGasBike.RunAtHalfSpeed();

            System.Console.WriteLine("::::::::DieselEngine:::::");
            IEngine   myDieEngine  = new DieselEngine(20);
            MotorBike myDieselBike = new MotorBike(myDieEngine);

            System.Console.WriteLine("Run at half speed.");
            myDieselBike.RunAtHalfSpeed();
        }
        static void Main(string[] args)
        {
            Car car = new Car("BMW", 5, "V8", 20);

            car.Display();

            MotorBike bike = new MotorBike("Honda", 3, "1000", 10);

            bike.Display();

            Rentalable rentableVehicle = new Rentalable(car);

            rentableVehicle.RentItem("Johnny");
            rentableVehicle.RentItem("Mary");

            rentableVehicle.Display();
        }
Beispiel #27
0
        public static MotorBike CreateMotorBike(eTypeOfVeichle i_TypeOfVeichile)
        {
            MotorBike motorBike = null;

            switch (i_TypeOfVeichile)
            {
            case eTypeOfVeichle.FuelMotorCycle:
                motorBike = new FuelMotorBike(s_FuelTypeForBike, s_MaxFuelForBike);
                break;

            case eTypeOfVeichle.ElectricMotorCycle:
                motorBike = new ElectricMotorBike(s_MaxTimeForBatteryForBike);
                break;
            }

            return(motorBike);
        }
Beispiel #28
0
        public IActionResult Put(int id, [FromBody] MotorBike value)
        {
            var b = _bikes.Where(x => x.Id == id).FirstOrDefault();

            if (b != null)
            {
                b.Name          = value.Name;
                b.Description   = value.Description;
                b.Make          = value.Make;
                b.Model         = value.Model;
                b.Power         = value.Power;
                b.Price         = value.Price;
                b.TopSpeed      = value.TopSpeed;
                b.Torque        = value.Torque;
                b.ZeroToHundred = value.ZeroToHundred;
            }
            return(Ok(b));
        }
        public ActionResult Create([Bind(Include = "ID,title,model,make,estimatedPrice,drivenInKms,documents,condition,imageUrl")] MotorBike motorBike, HttpPostedFileBase imgFile)
        {
            string fileName  = Path.GetFileNameWithoutExtension(imgFile.FileName);
            string extension = Path.GetExtension(imgFile.FileName);

            fileName           = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            motorBike.imageUrl = "/Images/" + fileName;
            fileName           = Path.Combine(Server.MapPath("~/Images/"), fileName);
            imgFile.SaveAs(fileName);
            motorBike.userID = User.Identity.GetUserId();
            //     if (ModelState.IsValid)
            //    {
            db.MotorBikes.Add(motorBike);
            db.SaveChanges();
            return(RedirectToAction("Create", "Users"));
            //   }

            //     return View(motorBike);
        }
        public async Task <Guid> NewMotorbike(string modelName, string regNumber, int odoMeter, Fuel typeOfFuel)
        {
            MotorBike motorbike = new MotorBike();

            motorbike.ModelName  = modelName;
            motorbike.RegNumber  = regNumber;
            motorbike.Odometer   = odoMeter;
            motorbike.RegDate    = DateTime.Now;
            motorbike.TypeOfFuel = typeOfFuel;
            motorbike.IdNumber   = Guid.NewGuid();


            List <MotorBike> Motorbikes = dataAccess.GetData <MotorBike>(FileName.Motorbike);

            Motorbikes.Add(motorbike);

            await dataAccess.SaveData <MotorBike>(Motorbikes, FileName.Motorbike);

            return(motorbike.IdNumber);
        }
Beispiel #31
0
        static void Main(string[] args)
        {
            Console.WriteLine("Car c");
            Car c = new Car(true);

            c.SteerLeft();
            c.SteerRight();
            c.Stop();

            Console.WriteLine("car car");
            Car car = new Car();

            car.Start();
            Console.WriteLine(car.IsOn);
            car.SteerLeft();
            car.SteerRight();
            //with private set it doesnt work
            //car.IsOn = false;
            car.Stop();
            Console.WriteLine(car.IsOn);


            Console.WriteLine("MotorBike moto");
            MotorBike moto = new MotorBike();

            moto.Start();
            Console.WriteLine(moto.IsOn);
            moto.SteerLeft();

            Console.WriteLine("MotorBike moto2");
            MotorBike moto2 = new MotorBike(true);

            Console.WriteLine(moto2.IsOn);
            moto2.SteerLeft();
            moto2.Stop();
            Console.WriteLine(moto2.IsOn);


            Console.ReadLine();
        }