public void DeleteVehicle(Vehicle vehicle) { if ((vehicle.EntityState == EntityState.Detached)) this.ObjectContext.Vehicles.Attach(vehicle); //Clear VehicleMaintenance vehicle.VehicleMaintenanceLog.Load(); var vehicleMaintenanceLogEntries = vehicle.VehicleMaintenanceLog.ToArray(); foreach (var vehicleMaintenanceLogEntry in vehicleMaintenanceLogEntries) this.DeleteVehicleMaintenanceLogEntry(vehicleMaintenanceLogEntry); //Remove routes from Vehicle vehicle.Routes.Load(); vehicle.Routes.Clear(); if ((vehicle.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(vehicle, EntityState.Deleted); } else { this.ObjectContext.Vehicles.DeleteObject(vehicle); } }
public void UpdateVehicle(Vehicle currentVehicle) { currentVehicle.LastModified = DateTime.UtcNow; currentVehicle.LastModifyingUserId = CurrentUserAccount().Id; this.ObjectContext.Vehicles.AttachAsModified(currentVehicle); }
/// <summary> /// Deprecated Method for adding a new object to the Vehicles EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToVehicles(Vehicle vehicle) { base.AddObject("Vehicles", vehicle); }
public void InsertVehicle(Vehicle vehicle) { if ((vehicle.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(vehicle, EntityState.Added); } else { this.ObjectContext.Vehicles.AddObject(vehicle); } }
/// <summary> /// Create a new Vehicle object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="businessAccountId">Initial value of the BusinessAccountId property.</param> /// <param name="createdDate">Initial value of the CreatedDate property.</param> public static Vehicle CreateVehicle(global::System.Guid id, global::System.Guid businessAccountId, global::System.DateTime createdDate) { Vehicle vehicle = new Vehicle(); vehicle.Id = id; vehicle.BusinessAccountId = businessAccountId; vehicle.CreatedDate = createdDate; return vehicle; }