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

View File

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

View File

@ -7,12 +7,19 @@ using Microsoft.EntityFrameworkCore;
namespace ScrumTaskboard.Controllers namespace ScrumTaskboard.Controllers
{ {
/// <summary>
/// This is a controller of Sprints class includes all API's related to the Sprints.
/// </summary>
[Route("[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class SprintsController : ControllerBase public class SprintsController : ControllerBase
{ {
private readonly TaskContext _context; private readonly TaskContext _context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="context"></param>
public SprintsController(TaskContext context) public SprintsController(TaskContext context)
{ {
_context = context; _context = context;
@ -64,23 +71,23 @@ namespace ScrumTaskboard.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<IActionResult> PutSprint(int id, ScrumSprint sprint) 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) if (id != sprint.id)
{ {
return BadRequest(); return BadRequest();
} }
// Speichere den geänderten Sprint im Context // Save the changed sprint in the context
_context.Entry(sprint).State = EntityState.Modified; _context.Entry(sprint).State = EntityState.Modified;
try try
{ {
// Übernehme die Änderungen in die Datenbank // Apply the changes to the database
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }
catch (DbUpdateConcurrencyException) 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)) if (!SprintExists(id))
{ {
return NotFound(); return NotFound();
@ -101,7 +108,7 @@ namespace ScrumTaskboard.Controllers
_context.Sprints.Add(sprint); _context.Sprints.Add(sprint);
await _context.SaveChangesAsync(); 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); return CreatedAtAction("GetSprint", new { id = sprint.id }, sprint);
} }
@ -115,16 +122,16 @@ namespace ScrumTaskboard.Controllers
return NotFound(); return NotFound();
} }
// Entferne den Sprint aus dem Context // Remove the sprint from the context
_context.Sprints.Remove(scrumSprint); _context.Sprints.Remove(scrumSprint);
// Speichere die Änderungen in der Datenbank // Save the changes in the database
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return scrumSprint; return scrumSprint;
} }
/// <summary> /// <summary>
/// Prüft, ob ein Sprint mit der angegebenen ID bereits existiert. /// Checks whether a sprint with the specified ID already exists.
/// </summary> /// </summary>
private bool SprintExists(int id) private bool SprintExists(int id)
{ {

View File

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

View File

@ -7,12 +7,19 @@ using Microsoft.EntityFrameworkCore;
namespace ScrumTaskboard.Controllers namespace ScrumTaskboard.Controllers
{ {
/// <summary>
/// This is a controller of Tasks class includes all API's related to the Tasks.
/// </summary>
[Route("[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class TasksController : ControllerBase public class TasksController : ControllerBase
{ {
private readonly TaskContext _context; private readonly TaskContext _context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="context"></param>
public TasksController(TaskContext context) public TasksController(TaskContext context)
{ {
_context = context; _context = context;
@ -73,23 +80,23 @@ namespace ScrumTaskboard.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<IActionResult> PutTask(int id, ScrumTask task) 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) if (id != task.id)
{ {
return BadRequest(); return BadRequest();
} }
// Speichere den geänderten Task im Context // Save the changed task in the context
_context.Entry(task).State = EntityState.Modified; _context.Entry(task).State = EntityState.Modified;
try try
{ {
// Übernehme die Änderungen in die Datenbank // Apply the changes to the database
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }
catch (DbUpdateConcurrencyException) 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)) if (!TaskExists(id))
{ {
return NotFound(); return NotFound();
@ -110,7 +117,7 @@ namespace ScrumTaskboard.Controllers
_context.Tasks.Add(task); _context.Tasks.Add(task);
await _context.SaveChangesAsync(); 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); return CreatedAtAction("GetTask", new { id = task.id }, task);
} }
@ -124,16 +131,16 @@ namespace ScrumTaskboard.Controllers
return NotFound(); return NotFound();
} }
// Entferne den Task aus dem Context // Remove the task from the context
_context.Tasks.Remove(scrumTask); _context.Tasks.Remove(scrumTask);
// Speichere die Änderungen in der Datenbank // Save the changes in the database
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return scrumTask; return scrumTask;
} }
/// <summary> /// <summary>
/// Prüft, ob ein Task mit der angegebenen ID bereits existiert. /// Checks whether a task with the specified ID already exists.
/// </summary> /// </summary>
private bool TaskExists(int id) private bool TaskExists(int id)
{ {

View File

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

View File

@ -7,12 +7,19 @@ using Microsoft.EntityFrameworkCore;
namespace ScrumTaskboard.Controllers namespace ScrumTaskboard.Controllers
{ {
/// <summary>
/// This is a controller of Userstories class includes all API's related to the Userstories.
/// </summary>
[Route("[controller]")] [Route("[controller]")]
[ApiController] [ApiController]
public class UserstoriesController : ControllerBase public class UserstoriesController : ControllerBase
{ {
private readonly TaskContext _context; private readonly TaskContext _context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="context"></param>
public UserstoriesController(TaskContext context) public UserstoriesController(TaskContext context)
{ {
_context = context; _context = context;
@ -77,23 +84,23 @@ namespace ScrumTaskboard.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<IActionResult> PutUserstory(int id, ScrumUserstory userstory) 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) if (id != userstory.id)
{ {
return BadRequest(); return BadRequest();
} }
// Speichere die geänderten Userstory im Context // Save the changed userstory in the context
_context.Entry(userstory).State = EntityState.Modified; _context.Entry(userstory).State = EntityState.Modified;
try try
{ {
// Übernehme die Änderungen in die Datenbank // Apply the changes to the database
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }
catch (DbUpdateConcurrencyException) 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)) if (!UserstoryExists(id))
{ {
return NotFound(); return NotFound();
@ -114,7 +121,7 @@ namespace ScrumTaskboard.Controllers
_context.Userstories.Add(userstory); _context.Userstories.Add(userstory);
await _context.SaveChangesAsync(); 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); return CreatedAtAction("GetUserstory", new { id = userstory.id }, userstory);
} }
@ -128,16 +135,16 @@ namespace ScrumTaskboard.Controllers
return NotFound(); return NotFound();
} }
// Entferne die Userstory aus dem Context // Remove the userstory from the context
_context.Userstories.Remove(userstory); _context.Userstories.Remove(userstory);
// Speichere die Änderungen in der Datenbank // Save the changes in the database
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return userstory; return userstory;
} }
/// <summary> /// <summary>
/// Prüft, ob eine Userstory mit der angegebenen ID bereits existiert. /// Checks whether a userstory with the specified ID already exists.
/// </summary> /// </summary>
private bool UserstoryExists(int id) private bool UserstoryExists(int id)
{ {