Example #1
0
        /// <summary>
        /// Register a new vehicle in the db
        /// </summary>
        /// <param name="vehiculo">Vehicle data</param>
        /// <param name="current">.</param>
        public override void registrarVehiculo(Vehiculo vehiculo, Current current = null)
        {
            _logger.LogDebug("RegistrarVehiculo request received.");
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();

                // TODO: Validation, if not throws VehicleException
                pc.Vehiculos.Add(vehiculo);
                pc.SaveChanges();
            }
        }
Example #2
0
        /// <summary>
        /// Register a new Person in the db
        /// </summary>
        /// <param name="persona">Persona data</param>
        /// <param name="current">.</param>
        public override void registrarPersona(Persona persona, Current current = null)
        {
            _logger.LogDebug("RegistrarPersona request received.");
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();

                // TODO: Validation, if not throws PersonaException
                pc.Personas.Add(persona);
                pc.SaveChanges();
            }
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logger">Logger DI</param>
        public SistemaImpl(ILogger <SistemaImpl> logger, IServiceScopeFactory serviceScopeFactory)
        {
            _logger = logger;
            _logger.LogDebug("Building SistemaImpl");

            // Database
            _serviceScopeFactory = serviceScopeFactory;
            _logger.LogDebug("Connecting to DB");

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();
                pc.Database.EnsureCreated();
                pc.SaveChanges();
            }
            _logger.LogDebug("Done");
        }
Example #4
0
        /// <summary>
        /// Register a new vehicle in the db
        /// </summary>
        /// <param name="vehiculo">Vehicle data</param>
        /// <param name="current">.</param>
        public override void registrarVehiculo(Vehiculo vehiculo, Current current = null)
        {
            _logger.LogDebug("RegistrarVehiculo request received.");
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();

                // Check if already is a vehcile with the same patente in the db
                if (pc.Personas.Find(vehiculo.patente) != null)
                {
                    _logger.LogDebug("Vehicle's patente already on DB");
                    throw new VehicleException("This vehicle patente is already registered on the db.");
                }

                pc.Vehiculos.Add(vehiculo);
                pc.SaveChanges();
            }
        }
Example #5
0
        /// <summary>
        /// Register a new Person in the db
        /// </summary>
        /// <param name="persona">Persona data</param>
        /// <param name="current">.</param>
        public override void registrarPersona(Persona persona, Current current = null)
        {
            _logger.LogDebug("RegistrarPersona request received.");
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();

                // Check if already is a persona with the same rut in db
                if (pc.Personas.Find(persona.rut) != null)
                {
                    _logger.LogDebug("Persona already on DB");
                    throw new PersonaException("Rut is already registered on the db.");
                }

                pc.Personas.Add(persona);
                pc.SaveChanges();
            }
        }