Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. private List<CarDTO> BuildCarsToDelete(IList<CarDTO> newCars, IList<CarDTO> existingCars)
  2. {
  3. var missingCars = new List<CarDTO>();
  4.  
  5. var cars = newCars.Select(c => c.CarId);
  6. var newCarIds = new HashSet<int>(cars);
  7.  
  8. foreach (var car in existingCars)
  9. {
  10. //If there are no new cars then it had some and they have been removed
  11. if (newCars.Count() == 0)
  12. {
  13. missingCars.Add(car);
  14. }
  15. else
  16. {
  17. if (!newCarIds.Contains(car.CarId))
  18. {
  19. missingCars.Add(car);
  20. }
  21. }
  22. }
  23.  
  24. return missingCars;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement