Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateParada(int id, [FromBody] Parada body)
        {
            // Open a db connection
            await Db.Connection.OpenAsync();

            // Create a new parada
            var query = new Parada(Db);
            // Find the parada with the passed id and asign it to result
            var result = await query.FindOne(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            // Update the properties
            result.nombre      = body.nombre;
            result.descripcion = body.descripcion;
            result.latitud     = body.latitud;
            result.longitud    = body.longitud;
            // Update the parada
            await result.UpdateAsync();

            // Return 200 ok with the updated object
            return(new ObjectResult(result));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetParada(int id)
        {
            // Open database connection
            await Db.Connection.OpenAsync();

            // Create a new parada
            var query = new Parada(Db);
            // Find the parada and asign it
            var result = await query.FindOne(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            // Return 200 ok and the found object
            return(new OkObjectResult(result));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteParada(int id)
        {
            // Open database connection
            await Db.Connection.OpenAsync();

            // Create a new parada
            var query = new Parada(Db);
            // Find one parada and asign it to a new value
            var result = await query.FindOne(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            await result.DeleteOneAsync();

            return(new OkResult());
        }