public async Task <IActionResult> GetOne(int id)
        {
            await Db.Connection.OpenAsync();

            var query  = new BlogPostQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            return(new OkObjectResult(result));
        }
        public async Task <IActionResult> GetOne(int id)
        {
            using (var db = new AppDb())
            {
                await db.Connection.OpenAsync();

                var query  = new BlogPostQuery(db);
                var result = await query.FindOneAsync(id);

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                return(new OkObjectResult(result));
            }
        }
        public async Task <IActionResult> PutOne(int id, [FromBody] BlogPost body)
        {
            await Db.Connection.OpenAsync();

            var query  = new BlogPostQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            result.Title   = body.Title;
            result.Content = body.Content;
            await result.UpdateAsync();

            return(new OkObjectResult(result));
        }
示例#4
0
        public async Task <IActionResult> GetOne(int id)
        {
            // Abrir una conexion
            await Db.Connection.OpenAsync();

            // Crear una instancai de la clase blogpostquery
            var query = new BlogPostQuery(Db);
            // Guardar el resultado edel query, se envia el parametro obtenido del url
            var result = await query.FindOneAsync(id);

            // Si returna nullo, retornan NotFound (404)
            if (result is null)
            {
                return(new NotFoundResult());
            }
            // Retornar OK y el resultado
            return(new OkObjectResult(result));
        }
示例#5
0
        public async Task <IActionResult> PutOne(int id, [FromBody] Role body)
        {
            await Db.Connection.OpenAsync();

            body.id = id;
            var query  = new BlogPostQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            // result.id = body.id;
            result.RoleName = body.RoleName;



            await query.UpdateAsync(body);

            return(new OkObjectResult(result));
        }
示例#6
0
        public async Task <IActionResult> DeleteOne(int id)
        {
            // Abrir una conexion
            await Db.Connection.OpenAsync();

            // Crear un query
            var query = new BlogPostQuery(Db);
            // Buscar un post con el id proporcionado
            var result = await query.FindOneAsync(id);

            // Si no existe un resultado, retornar 404
            if (result is null)
            {
                return(new NotFoundResult());
            }
            // Borrar el post
            await result.DeleteAsync();

            // Retornar Ok
            return(new OkResult());
        }
示例#7
0
        public async Task <IActionResult> PutOne(int id, [FromBody] BlogPost body)
        {
            // Abrir una conexion
            await Db.Connection.OpenAsync();

            // Crear un query
            var query = new BlogPostQuery(Db);
            // Buscar un post, con el id proporcionado
            var result = await query.FindOneAsync(id);

            // Si existe un resultado, retornar 404
            if (result is null)
            {
                return(new NotFoundResult());
            }
            // Actualizar las propiedades del post con el contenido en el cuerpo JSON
            result.Title   = body.Title;
            result.Content = body.Content;
            // Actualizar el blog
            await result.UpdateAsync();

            // Retornar Ok y el blog cambiado
            return(new OkObjectResult(result));
        }