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