Added Comments to the Controllers

This commit is contained in:
Taha FADL
2020-07-08 13:42:42 +02:00
parent faafbbeb62
commit 2cfdc85a90
7 changed files with 105 additions and 56 deletions

View File

@@ -7,12 +7,19 @@ using Microsoft.EntityFrameworkCore;
namespace ScrumTaskboard.Controllers
{
/// <summary>
/// This is a controller of Userstories class includes all API's related to the Userstories.
/// </summary>
[Route("[controller]")]
[ApiController]
public class UserstoriesController : ControllerBase
{
private readonly TaskContext _context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="context"></param>
public UserstoriesController(TaskContext context)
{
_context = context;
@@ -77,23 +84,23 @@ namespace ScrumTaskboard.Controllers
[HttpPut("{id}")]
public async Task<IActionResult> PutUserstory(int id, ScrumUserstory userstory)
{
// Die ID der Userstory darf nicht geändert werden
// The userstory's ID must not be changed
if (id != userstory.id)
{
return BadRequest();
}
// Speichere die geänderten Userstory im Context
// Save the changed userstory in the context
_context.Entry(userstory).State = EntityState.Modified;
try
{
// Übernehme die Änderungen in die Datenbank
// Apply the changes to the database
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
// Wenn die Userstory nicht existiert, gib Statuscode 404 zurück
// If the userstory does not exist, return status code 404
if (!UserstoryExists(id))
{
return NotFound();
@@ -114,7 +121,7 @@ namespace ScrumTaskboard.Controllers
_context.Userstories.Add(userstory);
await _context.SaveChangesAsync();
// Die neue Userstory wurde erstellt und kann über die GetUserstory Methode abgerufen werden.
// The new userstory has been created and can be called up using the GetUserstory method
return CreatedAtAction("GetUserstory", new { id = userstory.id }, userstory);
}
@@ -128,16 +135,16 @@ namespace ScrumTaskboard.Controllers
return NotFound();
}
// Entferne die Userstory aus dem Context
// Remove the userstory from the context
_context.Userstories.Remove(userstory);
// Speichere die Änderungen in der Datenbank
// Save the changes in the database
await _context.SaveChangesAsync();
return userstory;
}
/// <summary>
/// Prüft, ob eine Userstory mit der angegebenen ID bereits existiert.
/// Checks whether a userstory with the specified ID already exists.
/// </summary>
private bool UserstoryExists(int id)
{