public async Task <ConductorDTO> RegistrarInfraccion(RegistroInfraccionDTO registroInfraccionDTO) { var conductor = await _conductorRepo.GetConductorByDniAsync(registroInfraccionDTO.Dni); var vehiculo = await _vehiculosRepo.GetVehiculoByMatriculaAsync(registroInfraccionDTO.Matricula); var tipoInfraccion = await _infraccionRepo.GetByNombreAsync(registroInfraccionDTO.NombreInfraccion); if (conductor == null) { throw new ApiException("El conductor no existe"); } if (tipoInfraccion == null) { throw new ApiException("La Infraccion no existe"); } if (vehiculo == null) { throw new ApiException("El vehiculo no existe"); } conductor.Puntos -= tipoInfraccion.PuntosAdescontar; var registroI = new RegistroInfraccion(conductor, tipoInfraccion, vehiculo); _registroInfraccionesRepo.Insert(registroI); var res = await _registroInfraccionesRepo.Complete(); if (res <= 0) { throw new ApiException("Error al guardar los datos"); } return(new ConductorDTO { Apellidos = conductor.Apellidos, Dni = conductor.Dni, Nombre = conductor.Nombre, Puntos = conductor.Puntos }); }
public void Insert(RegistroInfraccion registroInfraccion) { _context.RegistroInfracciones.Add(registroInfraccion); }