private async Task <bool> HandleAsync(VehicleRegistered e) { Console.WriteLine($"Vehicle registered: License = {e.LicenseNumber}, Brand = {e.Brand}, Type = {e.Type}, Owner Id: {e.OwnerId}"); try { await _dbContext.Vehicles.AddAsync(new Vehicle { LicenseNumber = e.LicenseNumber, Brand = e.Brand, Type = e.Type, OwnerId = e.OwnerId }); await _dbContext.SaveChangesAsync(); } catch (DbUpdateException) { Console.WriteLine($"Skipped adding vehicle with license number {e.LicenseNumber}."); } return(true); }
private async Task <bool> HandleAsync(VehicleRegistered e) { Log.Information("Vehicle registered: {LicenseNumber}, {Brand}, {Type}, Owner Id: {OwnerId}", e.Matricula, e.Marca, e.Modelo, e.OwnerId); try { await _dbContext.Vehicles.AddAsync(new Vehicle { Matricula = e.Matricula, Marca = e.Marca, Modelo = e.Modelo, OwnerId = e.OwnerId }); await _dbContext.SaveChangesAsync(); } catch (DbUpdateException) { Console.WriteLine($"Skipped adding vehicle with matricula {e.Matricula}."); } return(true); }