Inheritance: IDto
        // POST /carsclient/cars
        public async Task<HttpResponseMessage> PostCar(Car car) {

            var createdCar = await _carsClient.AddCar(car);
            var response = Request.CreateResponse(HttpStatusCode.Created, createdCar);
            response.Headers.Location = new Uri(
                Url.Link("ClientHttpRoute", new { id = createdCar.Id }));

            return response;
        }
Ejemplo n.º 2
0
        // POST /api/cars
        public HttpResponseMessage PostCar(Car car)
        {
            var createdCar = _carsCtx.Add(car);
            var response = Request.CreateResponse(HttpStatusCode.Created, createdCar);
            response.Headers.Location = new Uri(
                Url.Link("ServerHttpRoute", new { id = createdCar.Id }));

            return response;
        }
Ejemplo n.º 3
0
        public bool TryUpdate(Car car)
        {
            Car oldCar;
            if (_carsDictionary.TryGetValue(car.Id, out oldCar)) {

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

            return false;
        }
Ejemplo n.º 4
0
        public Car Add(Car car)
        {
            lock (_incLock) {

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

            return car;
        }
Ejemplo n.º 5
0
        // PUT /api/cars/{id}
        public Car PutCar(int id, Car car)
        {
            car.Id = id;

            if (!_carsCtx.TryUpdate(car)) {

                var response = Request.CreateResponse(HttpStatusCode.NotFound);
                throw new HttpResponseException(response);
            }

            return car;
        }
        // PUT /carsclient/cars/{id}
        public async Task<Car> PutCar(int id, Car car) {

            var updatedCar = await _carsClient.UpdateCar(id, car);
            return updatedCar;
        }