public void AddVehicle(string claimNumber,VehicleInfoType veh) { var claim = _context.MitchellClaim.Include(c => c.Vehicles).Where(c => c.ClaimNumber == claimNumber).FirstOrDefault(); if( claim.Vehicles.Count > 0) { claim.Vehicles.Add(veh); } else { var list = new List<VehicleInfoType>(); list.Add(veh); claim.Vehicles = list; } _context.VehicleInfo.Add(veh); _context.SaveChanges(); }
public bool UpdateVehicle(string claimNumber, VehicleInfoType newVehicle) { bool isChanged = false; try { var claimToUpdate = _context.MitchellClaim.Include( c => c.Vehicles).Where(c => c.ClaimNumber == claimNumber).SingleOrDefault(); if (claimToUpdate != null) { var vehicleToUpdate = claimToUpdate.Vehicles.Where(v => v.Vin == newVehicle.Vin).SingleOrDefault(); if (vehicleToUpdate != null) { if (newVehicle.ExteriorColor != null && newVehicle.ExteriorColor != "" && newVehicle.ExteriorColor != vehicleToUpdate.ExteriorColor) { vehicleToUpdate.ExteriorColor = newVehicle.ExteriorColor; isChanged = true; } if (newVehicle.LicPlateExpDate != null && newVehicle.LicPlateExpDate != vehicleToUpdate.LicPlateExpDate) { vehicleToUpdate.LicPlateExpDate = newVehicle.LicPlateExpDate; isChanged = true; } //TODO more fields to update } } } catch (Exception ex) { _logger.LogError("vehicle update error", ex); return false; } return isChanged; }