Added all the basic methods for userstories
This commit is contained in:
parent
6a613ea05c
commit
f94274755c
@ -20,11 +20,96 @@ namespace ScrumTaskboard.Controllers
|
|||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: api/Tasks
|
// GET: api/userstories
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<IEnumerable<ScrumUserstory>>> GetUserstory()
|
public async Task<ActionResult<IEnumerable<ScrumUserstory>>> GetUserstory()
|
||||||
{
|
{
|
||||||
return await _context.Userstories.ToListAsync();
|
return await _context.Userstories.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET: api/userstories/1
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<ActionResult<ScrumUserstory>> GetUserstory(int id)
|
||||||
|
{
|
||||||
|
var userstory = await _context.Userstories.FindAsync(id);
|
||||||
|
|
||||||
|
if (userstory == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return userstory;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT: api/userstories/1
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<IActionResult> PutUserstory(int id, ScrumUserstory userstory)
|
||||||
|
{
|
||||||
|
// Die ID der Userstory darf nicht geändert werden
|
||||||
|
if (id != userstory.id)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Speichere die geänderten Userstory im Context
|
||||||
|
_context.Entry(userstory).State = EntityState.Modified;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Übernehme die Änderungen in die Datenbank
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
// Wenn die Userstory nicht existiert, gib Statuscode 404 zurück
|
||||||
|
if (!UserstoryExists(id))
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: api/userstories
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult<ScrumUserstory>> PostTask(ScrumUserstory userstory)
|
||||||
|
{
|
||||||
|
_context.Userstories.Add(userstory);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Die neue Userstory wurde erstellt und kann über die GetUserstory Methode abgerufen werden.
|
||||||
|
return CreatedAtAction("GetUserstory", new { id = userstory.id }, userstory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE: api/userstories/1
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<ActionResult<ScrumUserstory>> DeleteUserstory(int id)
|
||||||
|
{
|
||||||
|
var userstory = await _context.Userstories.FindAsync(id);
|
||||||
|
if (userstory == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Entferne die Userstory aus dem Context
|
||||||
|
_context.Userstories.Remove(userstory);
|
||||||
|
// Speichere die Änderungen in der Datenbank
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return userstory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prüft, ob eine Userstory mit der angegebenen ID bereits existiert.
|
||||||
|
/// </summary>
|
||||||
|
private bool UserstoryExists(int id)
|
||||||
|
{
|
||||||
|
return _context.Userstories.Any(e => e.id == id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user