コード例 #1
0
        public bool TryUpdate(Car car)
        {
            Car oldCar;
            if (_carsDictionary.TryGetValue(car.Id, out oldCar))
            {
                return _carsDictionary.TryUpdate(car.Id, car, oldCar);
            }

            return false;
        }
コード例 #2
0
        public Car Add(Car car)
        {
            lock (_incLock)
            {
                car.Id = _nextId;
                _carsDictionary.TryAdd(car.Id, car);
                _nextId++;
            }

            return car;
        }
コード例 #3
0
        public Car Put(int id, Car car)
        {
            car.Id = id;
            if (!_carsContext.TryUpdate(car))
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent("Car not found")
                };

                throw new HttpResponseException(response);
            }

            return car;
        }
コード例 #4
0
        public HttpResponseMessage Post(Car car)
        {

            _carsContext.Add(car);
            return new HttpResponseMessage(HttpStatusCode.Created);
        }