public static int ReturnPlaceId(JsonMoves.Day.Segment.Place place, DateTime startTime, DateTime endTime) { foreach (var item in places) { if (CheckIfSamePlace(item, place)) { item.AddVisit(startTime, endTime); return(item.id); } } Place newPlace = new Place(currentId++, place.name, place.location); places.Add(newPlace); newPlace.AddVisit(startTime, endTime); return(newPlace.id); }