Exemplo n.º 1
0
        public IActionResult Advertise(string id)
        {
            var vehicleModel = db.FindModel(id);
            var dto          = new VehicleDto()
            {
                ModelCode = vehicleModel.Code,
                ModelName = $"{vehicleModel.Manufacturer.Name} {vehicleModel.Name}"
            };

            return(View(dto));
        }
        public IActionResult Post([FromBody] VehicleDto dto)
        {
            var vehicleModel = db.FindModel(dto.ModelCode);
            var vehicle      = new Vehicle {
                Registration = dto.Registration,
                Color        = dto.Color,
                Year         = dto.Year,
                VehicleModel = vehicleModel
            };

            db.CreateVehicle(vehicle);
            return(Ok(dto));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] VehicleDto dto)
        {
            // If the vehicle already exists, return a 409 Conflict
            var existing = db.FindVehicle(dto.Registration);

            if (existing != default)
            {
                return(Conflict($"Sorry - we already have a car with registration {dto.Registration} in our database!"));
            }
            var vehicleModel = db.FindModel(dto.ModelCode);
            var vehicle      = new Vehicle {
                Registration = dto.Registration,
                Color        = dto.Color,
                Year         = dto.Year,
                VehicleModel = vehicleModel
            };

            db.CreateVehicle(vehicle);
            bus.PublishNewVehicleMessage(vehicle);
            return(Created($"/api/vehicles/{vehicle.Registration}", dto));
        }