Exemplo n.º 1
0
        // Add new
        public VehicleFull AddNew(VehiclePublic vehicle)
        {
            var v = ds.Vehicles.Add(Mapper.Map<Models.Vehicle>(vehicle));
            ds.SaveChanges();

            return Mapper.Map<ViewModels.VehicleFull>(v);
        }
Exemplo n.º 2
0
        // Add new
        public VehicleFull AddNew(VehiclePublic vehicle)
        {
            var v = ds.Vehicles.Add(Mapper.Map <Models.Vehicle>(vehicle));

            ds.SaveChanges();

            return(Mapper.Map <ViewModels.VehicleFull>(v));
        }
        // POST api/vehicles
        public HttpResponseMessage Post(VehiclePublic vehicle)
        {
            if (ModelState.IsValid)
            {
                // Add the new object
                var v = r.AddNew(vehicle);

                // Build the response object
                var response = Request.CreateResponse<VehicleFull>(HttpStatusCode.Created, v);

                // Set the Location header
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = v.Id }));

                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
            }
        }