Advertisement
dxeqtr

Untitled

Apr 8th, 2021
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public City Create(City newCity)
  2. {
  3.  
  4. MockDatabase.Cities.Add(newCity);
  5.  
  6. return newCity;
  7. }
  8.  
  9. public bool Delete(int id)
  10. {
  11. var city = MockDatabase.Cities.FirstOrDefault(c => c.Id == id);
  12.  
  13. return MockDatabase.Cities.Remove(city);
  14. }
  15.  
  16. public City Get(int id)
  17. {
  18. var city = MockDatabase.Cities.FirstOrDefault(c => c.Id == id);
  19.  
  20. if (city == null)
  21. {
  22. throw new ArgumentNullException();
  23. }
  24.  
  25. return city;
  26. }
  27.  
  28. public List<City> GetAll()
  29. {
  30. return MockDatabase.Cities;
  31. }
  32.  
  33. public City Update(int id, string newName, int newCountry)
  34. {
  35.  
  36. var city = MockDatabase.Cities.FirstOrDefault(c => c.Id == id);
  37.  
  38. if (city == null)
  39. {
  40. throw new ArgumentNullException();
  41. }
  42.  
  43. city.Name = newName;
  44. city.CountryId = newCountry;
  45. return city;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement