Merge branch 'master' into feature/api-explorer
This commit is contained in:
commit
de082945ab
|
@ -0,0 +1,113 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ScrumTaskboard.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class ProjectsController : ControllerBase
|
||||
{
|
||||
private readonly TaskContext _context;
|
||||
|
||||
public ProjectsController(TaskContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/projects
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumProject>>> GetProject()
|
||||
{
|
||||
return await _context.Projects.ToListAsync();
|
||||
}
|
||||
|
||||
// GET: api/projects/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<ScrumProject>> GetProjects(int id)
|
||||
{
|
||||
var Project = await _context.Projects.FindAsync(id);
|
||||
|
||||
if (Project == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Project;
|
||||
}
|
||||
|
||||
// PUT: api/Project/5
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutProject(int id, ScrumProject projects)
|
||||
{
|
||||
// Die ID des Projects darf nicht geändert werden
|
||||
if (id != projects.id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
// Speichere den geänderten Project im Context
|
||||
_context.Entry(projects).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
// Übernehme die Änderungen in die Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
// Wenn der Project nicht existiert, gib Statuscode 404 zurück
|
||||
if (!ProjectExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// POST: api/Project
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ScrumProject>> PostProject(ScrumProject projects)
|
||||
{
|
||||
_context.Projects.Add(projects);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Der neue Project wurde erstellt und kann über die GetProject Methode abgerufen werden.
|
||||
return CreatedAtAction("GetProject", new { id = projects.id }, projects);
|
||||
}
|
||||
|
||||
// DELETE: api/Project/5
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult<ScrumProject>> DeleteProject(int id)
|
||||
{
|
||||
var scrumProject = await _context.Projects.FindAsync(id);
|
||||
if (scrumProject == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Entferne den Project aus dem Context
|
||||
_context.Projects.Remove(scrumProject);
|
||||
// Speichere die Änderungen in der Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return scrumProject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prüft, ob ein Project mit der angegebenen ID bereits existiert.
|
||||
/// </summary>
|
||||
private bool ProjectExists(int id)
|
||||
{
|
||||
return _context.Projects.Any(e => e.id == id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ namespace ScrumTaskboard.Controllers
|
|||
|
||||
// GET: api/sprint
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumSprint>>> GetSprints()
|
||||
public async Task<ActionResult<IEnumerable<ScrumSprint>>> GetSprint()
|
||||
{
|
||||
return await _context.Sprints.ToListAsync();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace ScrumTaskboard.Controllers
|
|||
return Sprint;
|
||||
}
|
||||
|
||||
// PUT: api/Sprint/5
|
||||
// PUT: api/sprint/5
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutSprint(int id, ScrumSprint sprint)
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace ScrumTaskboard
|
|||
public DbSet<ScrumCategory> Categories { get; set; }
|
||||
public DbSet<ScrumSprint> Sprints { get; set; }
|
||||
public DbSet<ScrumStatus> Status { get; set; }
|
||||
public DbSet<ScrumProject> Projects { get; set; }
|
||||
|
||||
public TaskContext() { }
|
||||
|
||||
|
@ -71,4 +72,11 @@ namespace ScrumTaskboard
|
|||
public string title { get; set; }
|
||||
public string description { get; set; }
|
||||
}
|
||||
|
||||
public class ScrumProject
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string title { get; set; }
|
||||
public bool isprivate { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue