コード例 #1
0
        public async Task <IActionResult> FindOneAsync(int id)
        {
            using (_db)
            {
                await _db.Connection.OpenAsync();

                var query  = new PostQuery(_db);
                var result = await query.FindOneAsync(id);

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                return(new OkObjectResult(result));
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetOne(int id)
        {
            using (var db = new AppDb(connection_string))
            {
                await db.Connection.OpenAsync();

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

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                return(new OkObjectResult(result));
            }
        }
コード例 #3
0
        public async Task <IActionResult> PutOne(int id, [FromBody] Post body)
        {
            using (var db = new AppDb(connection_string))
            {
                await db.Connection.OpenAsync();

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

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

                return(new OkObjectResult(result));
            }
        }