示例#1
0
        public int AddCar(CarViewModel car)
        {
            Console.WriteLine("===================================");
            Console.WriteLine("AddCar: Adding car to repository... IN CAR SERVICE.CS");
            Console.WriteLine("===================================");

            var manufacturerId = CheckManufacturerByName(car.manufacturer);
            var modelId        = CheckModelByName(manufacturerId, car.model);

            int fuelTypeCount = Count(car.fuelType);

            Car newCar = new Car()
            {
                LicenceNumber  = car.regNum,
                ManufacturerID = manufacturerId,
                ModelID        = modelId,
                Year           = car.year,
                CO2            = car.co2,
                Color          = car.color,
                Status         = car.status,
                Doors          = car.doors,
                Seating        = car.seating,
                Milage         = car.driven,
                Cylinders      = car.cylinders,
                Horsepower     = car.horsepower,
                Injection      = car.injection,
                CC             = car.cc,
                Weight         = car.weight,
                Hybrid         = fuelTypeCount > 1,
                DriveID        = car.drive,
                TransmissionID = car.transmission
            };


            var      carID     = _repo.AddCar(newCar);
            DateTime localDate = DateTime.Now;

            Console.WriteLine("=====================");
            Console.WriteLine("Inni í AddCar service.cs");
            Console.WriteLine("=====================");

            SaleInfo newInfo = new SaleInfo()
            {
                CarSaleID    = car.carSaleId,
                CarID        = carID,
                DateOnSale   = localDate,
                DateOfUpdate = localDate,
                SellerID     = 0,
                Price        = car.price,
                OnSite       = car.onSite
            };

            var check = _repo.AddSellerInfo(newInfo);

            Console.WriteLine("=====================");
            Console.WriteLine("Adding Wheel types to Car - in CarService.cs");
            Console.WriteLine("=====================");

            foreach (var wheelId in car.wheel)
            {
                WheelCar wc = new WheelCar()
                {
                    CarID    = carID,
                    WheelID  = wheelId,
                    Quantity = 4
                };

                _repo.AddWheelCar(wc);
                Console.WriteLine("  Adding " + wc.ToString());
            }

            foreach (var fuelId in car.fuelType)
            {
                FuelTypeCar fc = new FuelTypeCar()
                {
                    CarID      = carID,
                    FuelTypeID = fuelId,
                };

                _repo.AddFuelTypeCar(fc);
                Console.WriteLine("  Adding " + fc.ToString());
            }

            foreach (var driveSteeringId in car.driveSteering)
            {
                DriveSteeringInfoCar dc = new DriveSteeringInfoCar()
                {
                    CarID           = carID,
                    DriveSteeringID = driveSteeringId,
                };

                _repo.AddDriveSteeringInfoCar(dc);
                Console.WriteLine("Adding DRIVESTEERING " + dc.ToString());
            }

            return(carID);
        }