Added the files.
This commit is contained in:
commit
1553e6b971
315 changed files with 56809 additions and 0 deletions
107
Controllers/TodoItemsController.cs
Executable file
107
Controllers/TodoItemsController.cs
Executable file
|
@ -0,0 +1,107 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TodoApi.Models;
|
||||
|
||||
namespace TodoApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class TodoItemsController : ControllerBase
|
||||
{
|
||||
private readonly TodoContext _context;
|
||||
|
||||
public TodoItemsController(TodoContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/TodoItems
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<TodoItem>>> GetTodoItems()
|
||||
{
|
||||
return await _context.TodoItems.ToListAsync();
|
||||
}
|
||||
|
||||
// GET: api/TodoItems/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<TodoItem>> GetTodoItem(long id)
|
||||
{
|
||||
var todoItem = await _context.TodoItems.FindAsync(id);
|
||||
|
||||
if (todoItem == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return todoItem;
|
||||
}
|
||||
|
||||
// PUT: api/TodoItems/5
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutTodoItem(long id, TodoItem todoItem)
|
||||
{
|
||||
if (id != todoItem.Id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(todoItem).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!TodoItemExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// POST: api/TodoItems
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<TodoItem>> PostTodoItem(TodoItem todoItem)
|
||||
{
|
||||
_context.TodoItems.Add(todoItem);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);
|
||||
}
|
||||
|
||||
// DELETE: api/TodoItems/5
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteTodoItem(long id)
|
||||
{
|
||||
var todoItem = await _context.TodoItems.FindAsync(id);
|
||||
if (todoItem == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_context.TodoItems.Remove(todoItem);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
private bool TodoItemExists(long id)
|
||||
{
|
||||
return _context.TodoItems.Any(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue