예제 #1
0
        public CarModel UpdateCar(CarModel carModel)
        {
            Car car = DB.Cars.SingleOrDefault(p => p.CarId == carModel.CarId);

            if (car == null)
            {
                return(null);
            }

            if (carModel.IsFixed == true && car.IsFixed != 1)
            {
                car.IsFixed = 1;
            }
            if (carModel.IsFixed == false && car.IsFixed != 0)
            {
                car.IsFixed = 0;
            }

            if (car.Km != carModel.Km)
            {
                car.Km = carModel.Km;
            }

            CarsBranch carsBranch = DB.CarsBranches.SingleOrDefault(p => p.CarId == car.CarId);

            if (DB.Branches.SingleOrDefault(p => p.BranchId == carsBranch.BranchId).Name != carModel.Branch)
            {
                carsBranch.BranchId = DB.Branches.SingleOrDefault(p => p.Name == carModel.Branch).BranchId;
            }

            DB.SaveChanges();

            return(carModel);
        }
예제 #2
0
        public CarModel AddCar(CarModel carModel)
        {
            Car car = carModel.ConvertToCar();

            using (DB.Database.BeginTransaction())
            {
                DB.Cars.Add(car);
                DB.SaveChanges();


                CarsBranch carsBranch = new CarsBranch();

                carsBranch.CarId    = car.CarId;
                carsBranch.BranchId = DB.Branches.SingleOrDefault(p => p.Name == carModel.Branch).BranchId;

                DB.CarsBranches.Add(carsBranch);
                DB.SaveChanges();

                DB.Database.CommitTransaction();
            }

            carModel.CarId = car.CarId;

            return(carModel);
        }
예제 #3
0
 public CarsBranchModel(CarsBranch carsBranch)
 {
     CarBranchId = carsBranch.CarBranchId;
     CarId       = carsBranch.CarId;
     BranchId    = carsBranch.BranchId;
 }