예제 #1
0
        /// <summary>
        /// Register an access to the the UCN
        /// </summary>
        /// <param name="patente">patente of the vehicle</param>
        /// <param name="porteria">Access gate</param>
        /// <param name="current">.</param>
        /// <returns>The access</returns>
        /// <exception cref="VehicleNotFoundException">If the vehicle is not in the db</exception>
        public override Acceso registrarAcceso(string patente, Porteria porteria, Current current = null)
        {
            _logger.LogDebug("RegistrarAcceso request received.");

            // Check if the patente exist in db
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();

                if (pc.Vehiculos.Find(patente) == null)
                {
                    _logger.LogError("Invalid vehicle: " + patente);
                    throw new VehicleException("Vehicle not found on db");
                }

                // Vehicle found, create access
                var ac = new Acceso
                {
                    patente  = patente,
                    porteria = porteria,
                    // dd/mm/yy hh:mm:ss
                    horaEntrada = DateTime.Now.ToString("G")
                };

                pc.Accesos.Add(ac);
                _logger.LogInformation("New access: ", ac.ToString());
                return(ac);
            }
        }
예제 #2
0
 /// <summary>
 /// Returns a list with all vehicles on the DB.
 /// </summary>
 /// <param name="current">.</param>
 /// <returns>A Vehiculo Array.</returns>
 public override Vehiculo[] getVehiculos(Current current = null)
 {
     _logger.LogDebug("GetVehiculos request received.");
     using (var scope = _serviceScopeFactory.CreateScope())
     {
         ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();
         return(pc.Vehiculos.ToArray());
     }
 }
예제 #3
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();
            }
        }
예제 #4
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();
            }
        }
예제 #5
0
 /// <summary>
 /// Returns a list with all the Accesos on the DB.
 /// </summary>
 /// <param name="current">.</param>
 /// <returns>An Accesos Array</returns>
 public override Acceso[] getAccesos(Current current = null)
 {
     _logger.LogDebug("GetPersonas request received.");
     using (var scope = _serviceScopeFactory.CreateScope())
     {
         ParkingContext pc = scope.ServiceProvider.GetService <ParkingContext>();
         foreach (var a in pc.Accesos)
         {
             _logger.LogDebug(a.patente);
         }
         return(pc.Accesos.ToArray());
     }
 }
예제 #6
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");
        }
예제 #7
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();
            }
        }
예제 #8
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();
            }
        }
예제 #9
0
        /// <summary>
        /// Find a Vehiculo in the db by its patente.
        /// </summary>
        /// <param name="patente">Vehiculo's patente</param>
        /// <param name="current">.</param>
        /// <returns>A Vehiculo</returns>
        /// <exception cref="VehicleException">If the Vehiculo wasn't found</exception>
        public override Vehiculo findVehiculoByPatente(string patente, Current current = null)
        {
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                _logger.LogDebug("Searching for Vehiculo with patente: " + patente);
                ParkingContext pc       = scope.ServiceProvider.GetService <ParkingContext>();
                var            vehiculo = pc.Vehiculos.Find(patente);

                if (vehiculo != null)
                {
                    _logger.LogDebug("Vehiculo found!");
                    return(vehiculo);
                }

                else
                {
                    _logger.LogDebug("Vehiculo not found!");
                    throw new VehicleException("Vehiculo not found");
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Find a Persona in the db by its rut.
        /// </summary>
        /// <param name="rut">Persona's rut</param>
        /// <param name="current">.</param>
        /// <returns>A Persona</returns>
        /// <exception cref="PersonaException">If the Persona wasn't found</exception>
        public override Persona findPersonaByRut(string rut, Current current = null)
        {
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                _logger.LogDebug("Searching for Persona with rut: " + rut);
                ParkingContext pc      = scope.ServiceProvider.GetService <ParkingContext>();
                var            persona = pc.Personas.Find(rut);

                if (persona != null)
                {
                    _logger.LogDebug("Persona found!");
                    return(persona);
                }

                else
                {
                    _logger.LogDebug("Persona not found!");
                    throw new PersonaException("Persona not found");
                }
            }
        }