public void AddLocation(Location location) { List <Location> locations = GetAllLocations(); locations.Add(location); JsonFileWriter <Location> .WriteToJson(locations, JsonFileName); }
public void AddPizza(Pizza pizza) { //Created a dictionary that calls the GetAllPizzas so it populates it with the existing pizzas. //then we add the new pizza to it, and then afterwards write to Json the created dictionary (existingPizzas) //Dictionary<int, Pizza> existingPizzas = GetAllPizzas(); Pizzas = GetAllPizzas(); Pizzas.Add(pizza.Id, pizza); JsonFileWriter.WriteToJson(Pizzas, filePath); }
public void DeleteLocation(int id) { Location locationToDelete = GetLocation(id); List <Location> locations = GetAllLocations(); if (locationToDelete != null) { if (locations.Remove(locationToDelete)) { JsonFileWriter.WriteToJson(locations, filePath); } } }
public void DeleteSpeedMeasurement(int id) { SpeedMeasurement speedMeasurementToDelete = GetSpeedMeasurement(id); List <SpeedMeasurement> measurements = GetAllSpeedMeasurements(); if (speedMeasurementToDelete != null) { if (measurements.Remove(speedMeasurementToDelete)) { JsonFileWriter.WriteToJson(measurements, filePath); } } }
public void AddLocation(Location location) { List <Location> locations = GetAllLocations(); if (IdExist(location.Id)) { throw new UniqIdException("Id is in use. Please choose another id"); } else { locations.Add(location); } JsonFileWriter.WriteToJson(locations, filePath); }
public void AddSpeedMeasurement(int speed, Location location, string imageName) { List <SpeedMeasurement> measurements = GetAllSpeedMeasurements(); if (speed > 0 && speed <= 300) { measurements.Add(new SpeedMeasurement(speed, location, imageName)); } else { throw new CalibrationException($"Incorrect speed {speed} km/t - something went wrong!"); } JsonFileWriter.WriteToJson(measurements, filePath); }
public void DeleteLocation(int id) { List <Location> LocationList = GetAllLocations(); for (int i = 0; i < LocationList.Count; i++) { if (LocationList[i].Id == id) { LocationList.Remove(LocationList[i]); break; } } JsonFileWriter <Location> .WriteToJson(LocationList, JsonFileName); }
public void UpdateLocation(Location location) { List <Location> LocationList = GetAllLocations(); for (int i = 0; i < LocationList.Count; i++) { if (location.Id == LocationList[i].Id) { LocationList[i] = location; break; } } JsonFileWriter <Location> .WriteToJson(LocationList, JsonFileName); }
public void DeleteSpeedMeasurement(int id) { List <SpeedMeasurement> speedMeasurementsList = GetAllSpeedMeasurements(); for (int i = 0; i < speedMeasurementsList.Count; i++) { if (speedMeasurementsList[i].Id == id) { speedMeasurementsList.Remove(speedMeasurementsList[i]); break; } } JsonFileWriter <SpeedMeasurement> .WriteToJson(speedMeasurementsList, JsonFileName); }
public void UpdateLocation(Location location) { List <Location> locations = GetAllLocations(); if (location != null) { foreach (Location l in locations) { if (l.Id == location.Id) { l.Id = location.Id; l.Address = location.Address; l.SpeedLimit = location.SpeedLimit; l.Zone = location.Zone; } } } JsonFileWriter.WriteToJson(locations, filePath); }
public void UpdateEvent(Event ev) { if (ev != null) { List <Event> events = GetAllEvents(); foreach (var e in events) { if (e.Id == ev.Id) { e.Id = ev.Id; e.Name = ev.Name; e.City = ev.City; e.Description = ev.Description; e.DateTime = ev.DateTime; } } JsonFileWriter.WriteToJson(events, filePath); } }
public void UpdateEvent(Event Event) { List <Event> events = GetAllEvents(); if (Event != null) { foreach (Event e in events) { if (e.Id == Event.Id) { e.Id = Event.Id; e.Name = Event.Name; e.City = Event.City; e.Description = Event.Description; e.DateTime = Event.DateTime; } } } JsonFileWriter.WriteToJson(events, filePath); }
public void AddSpeedMeasurement(int speed, Location location, string imageName) { if (speed <= 0 || speed > 300) { throw new CalibrationException($"{speed} is an invalid speed."); } List <SpeedMeasurement> speedMeasurementsList = GetAllSpeedMeasurements(); speedMeasurementsList.Add(new SpeedMeasurement() { Id = GetHighestSpeedMeasurementId() + 1, TimeStamp = DateTime.Now, Speed = speed, Location = location, Image = imageName }); JsonFileWriter <SpeedMeasurement> .WriteToJson(speedMeasurementsList, JsonFileName); }
public void AddEvent(Event ev) { List <int> eventsIds = new List <int>(); List <Event> events = GetAllEvents(); foreach (var evt in events) { eventsIds.Add(evt.Id); } if (eventsIds.Count != 0) { int start = eventsIds.Max(); ev.Id = start + 1; } else { ev.Id = 1; } events.Add(ev); JsonFileWriter.WriteToJson(events, filePath); }