public bool TryUpdate(Car car) {

            Car oldCar;
            if (_carsDictionary.TryGetValue(car.Id, out oldCar)) {

                return _carsDictionary.TryUpdate(car.Id, car, oldCar);
            }

            return false;
        }
        public Car Add(Car car) {

            lock (_incLock) {

                car.Id = _nextId;
                _carsDictionary.TryAdd(car.Id, car);
                _nextId++;
            }

            return car;
        }
예제 #3
0
        public void Add(Car car) {

            int maxId = 1;

            if (cars.Any()) {

                maxId = cars.Max(x => x.Id);
            }

            car.Id = maxId + 1;

            cars.Add(car);
        }