Exemplo n.º 1
0
        public async Task <ActionResult> Post([FromBody] VehicleCreationDTO vehicleCreation)
        {
            var vehicle = mapper.Map <Vehicle>(vehicleCreation);

            context.Add(vehicle);
            await context.SaveChangesAsync();

            var vehicleDTO = mapper.Map <VehicleDTO>(vehicle);

            return(new CreatedAtRouteResult("getVehicle", new { vehicleDTO.Id }, vehicleDTO));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Put(int id, [FromBody] VehicleCreationDTO vehicleCreation)
        {
            var vehicle = mapper.Map <Vehicle>(vehicleCreation);

            vehicle.Id = id;
            context.Entry(vehicle
                          ).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(NoContent());
        }
        private List <VehicleCoverage> MapVehicleCoverage(VehicleCreationDTO vehicleCreationDTO, Vehicle vehicle)
        {
            var result = new List <VehicleCoverage>();

            foreach (var id in vehicleCreationDTO.CoverageIds)
            {
                result.Add(new VehicleCoverage()
                {
                    CoverageId = id
                });
            }
            return(result);
        }