Exemplo n.º 1
0
        public CarFleetModel AddCar(CarFleetModel carFleetModel)
        {
            CarFleet carFleet = carFleetModel.ConvertToCarFleet();

            DB.CarFleets.Add(carFleet);
            DB.SaveChanges();
            carFleetModel.ID = carFleet.CarFleetId;
            return(carFleetModel);
        }
Exemplo n.º 2
0
        public CarFleetModel UpdatePartialCarFleet(CarFleetModel carFleetModel)
        {
            CarFleet carToUpdate = DB.CarFleets.SingleOrDefault(c => c.CarFleetId == carFleetModel.ID);

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

            if (carToUpdate.ManufacturerId != null)
            {
                carToUpdate.ManufacturerId = carFleetModel.ManufacturerID;
            }

            if (carToUpdate.Model != null)
            {
                carToUpdate.Model = carFleetModel.Model;
            }

            if (carToUpdate.DailyCost != null)
            {
                carToUpdate.DailyCost = carFleetModel.DailyCost;
            }

            if (carToUpdate.LateDayCost != null)
            {
                carToUpdate.LateDayCost = carFleetModel.LateDayCost;
            }

            if (carToUpdate.YearOfManufacturer != null)
            {
                carToUpdate.YearOfManufacturer = carFleetModel.YearOfManufacturer;
            }

            if (carToUpdate.Gear != null)
            {
                carToUpdate.Gear = carFleetModel.Gear;
            }
            DB.SaveChanges();
            return(carFleetModel);
        }