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 Tasks class includes all API's related to the Tasks.
/// </summary>
[Route("[controller]")]
[ApiController]
public class TasksController : ControllerBase
{
private readonly TaskContext _context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="context"></param>
public TasksController(TaskContext context)
{
_context = context;
@@ -73,23 +80,23 @@ namespace ScrumTaskboard.Controllers
[HttpPut("{id}")]
public async Task<IActionResult> PutTask(int id, ScrumTask task)
{
// Die ID des Tasks darf nicht geändert werden
// The task's ID must not be changed
if (id != task.id)
{
return BadRequest();
}
// Speichere den geänderten Task im Context
// Save the changed task in the context
_context.Entry(task).State = EntityState.Modified;
try
{
// Übernehme die Änderungen in die Datenbank
// Apply the changes to the database
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
// Wenn der Task nicht existiert, gib Statuscode 404 zurück
// If the task does not exist, return status code 404
if (!TaskExists(id))
{
return NotFound();
@@ -110,7 +117,7 @@ namespace ScrumTaskboard.Controllers
_context.Tasks.Add(task);
await _context.SaveChangesAsync();
// Der neue Task wurde erstellt und kann über die GetTask Methode abgerufen werden.
// The new task has been created and can be called up using the GetTask method
return CreatedAtAction("GetTask", new { id = task.id }, task);
}
@@ -124,16 +131,16 @@ namespace ScrumTaskboard.Controllers
return NotFound();
}
// Entferne den Task aus dem Context
// Remove the task from the context
_context.Tasks.Remove(scrumTask);
// Speichere die Änderungen in der Datenbank
// Save the changes in the database
await _context.SaveChangesAsync();
return scrumTask;
}
/// <summary>
/// Prüft, ob ein Task mit der angegebenen ID bereits existiert.
/// Checks whether a task with the specified ID already exists.
/// </summary>
private bool TaskExists(int id)
{