Added filters for all get-all endpoints
This commit is contained in:
parent
48d5622c0f
commit
8a26b957aa
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -21,7 +22,23 @@ namespace ScrumTaskboard.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumCategory>>> GetCategory()
|
||||
{
|
||||
return await _context.Categories.ToListAsync();
|
||||
IEnumerable<ScrumCategory> filtered = _context.Categories;
|
||||
if (HttpContext.Request.Query["title"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumCategory>(c => c.title.Contains(HttpContext.Request.Query["title"].ToString()));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["projectid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumCategory>(c => c.projectid == Convert.ToInt32(HttpContext.Request.Query["projectid"]));
|
||||
}
|
||||
if (HttpContext.Request.Query["color"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumCategory>(c => c.color == HttpContext.Request.Query["color"].ToString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
return filtered.ToList();
|
||||
}
|
||||
|
||||
// GET: api/category/1
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -21,7 +22,17 @@ namespace ScrumTaskboard.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumProject>>> GetProject()
|
||||
{
|
||||
return await _context.Projects.ToListAsync();
|
||||
IEnumerable<ScrumProject> filtered = _context.Projects;
|
||||
if (HttpContext.Request.Query["title"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumProject>(t => t.title.Contains(HttpContext.Request.Query["title"].ToString()));
|
||||
}
|
||||
if (HttpContext.Request.Query["isprivate"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumProject>(t => t.isprivate == Convert.ToBoolean(HttpContext.Request.Query["isprivate"]));
|
||||
}
|
||||
|
||||
return filtered.ToList();
|
||||
}
|
||||
|
||||
// GET: api/projects/5
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -21,92 +22,110 @@ namespace ScrumTaskboard.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumSprint>>> GetSprint()
|
||||
{
|
||||
return await _context.Sprints.ToListAsync();
|
||||
}
|
||||
|
||||
// GET: api/sprint/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<ScrumSprint>> GetSprint(int id)
|
||||
{
|
||||
var Sprint = await _context.Sprints.FindAsync(id);
|
||||
|
||||
if (Sprint == null)
|
||||
IEnumerable<ScrumSprint> filtered = _context.Sprints;
|
||||
if (HttpContext.Request.Query["title"].ToString() != "")
|
||||
{
|
||||
return NotFound();
|
||||
filtered = filtered.Where<ScrumSprint>(s => s.title.Contains(HttpContext.Request.Query["title"].ToString()));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["projectid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumSprint>(s => s.projectid == Convert.ToInt32(HttpContext.Request.Query["projectid"]));
|
||||
}
|
||||
if (HttpContext.Request.Query["startDate"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumSprint>(s => s.startDate == DateTime.Parse(HttpContext.Request.Query["startDate"].ToString()));
|
||||
}
|
||||
if (HttpContext.Request.Query["endDate"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumSprint>(s => s.endDate == DateTime.Parse(HttpContext.Request.Query["startDate"].ToString()));
|
||||
}
|
||||
|
||||
return Sprint;
|
||||
}
|
||||
|
||||
// PUT: api/sprint/5
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutSprint(int id, ScrumSprint sprint)
|
||||
{
|
||||
// Die ID des Sprints darf nicht geändert werden
|
||||
if (id != sprint.id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
// Speichere den geänderten Sprint im Context
|
||||
_context.Entry(sprint).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
// Übernehme die Änderungen in die Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
// Wenn der Sprint nicht existiert, gib Statuscode 404 zurück
|
||||
if (!SprintExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// POST: api/Sprint
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ScrumSprint>> PostSprint(ScrumSprint sprint)
|
||||
{
|
||||
_context.Sprints.Add(sprint);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Der neue Sprint wurde erstellt und kann über die GetSprint Methode abgerufen werden.
|
||||
return CreatedAtAction("GetSprint", new { id = sprint.id }, sprint);
|
||||
}
|
||||
|
||||
// DELETE: api/Sprint/5
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult<ScrumSprint>> DeleteSprint(int id)
|
||||
{
|
||||
var scrumSprint = await _context.Sprints.FindAsync(id);
|
||||
if (scrumSprint == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Entferne den Sprint aus dem Context
|
||||
_context.Sprints.Remove(scrumSprint);
|
||||
// Speichere die Änderungen in der Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return scrumSprint;
|
||||
}
|
||||
|
||||
return filtered.ToList();
|
||||
}
|
||||
|
||||
// GET: api/sprint/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<ScrumSprint>> GetSprint(int id)
|
||||
{
|
||||
var Sprint = await _context.Sprints.FindAsync(id);
|
||||
|
||||
if (Sprint == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Sprint;
|
||||
}
|
||||
|
||||
// PUT: api/sprint/5
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutSprint(int id, ScrumSprint sprint)
|
||||
{
|
||||
// Die ID des Sprints darf nicht geändert werden
|
||||
if (id != sprint.id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
// Speichere den geänderten Sprint im Context
|
||||
_context.Entry(sprint).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
// Übernehme die Änderungen in die Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
// Wenn der Sprint nicht existiert, gib Statuscode 404 zurück
|
||||
if (!SprintExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// POST: api/Sprint
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ScrumSprint>> PostSprint(ScrumSprint sprint)
|
||||
{
|
||||
_context.Sprints.Add(sprint);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Der neue Sprint wurde erstellt und kann über die GetSprint Methode abgerufen werden.
|
||||
return CreatedAtAction("GetSprint", new { id = sprint.id }, sprint);
|
||||
}
|
||||
|
||||
// DELETE: api/Sprint/5
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult<ScrumSprint>> DeleteSprint(int id)
|
||||
{
|
||||
var scrumSprint = await _context.Sprints.FindAsync(id);
|
||||
if (scrumSprint == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Entferne den Sprint aus dem Context
|
||||
_context.Sprints.Remove(scrumSprint);
|
||||
// Speichere die Änderungen in der Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return scrumSprint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prüft, ob ein Sprint mit der angegebenen ID bereits existiert.
|
||||
/// </summary>
|
||||
private bool SprintExists(int id)
|
||||
{
|
||||
return _context.Sprints.Any(e => e.id == id);
|
||||
}
|
||||
private bool SprintExists(int id)
|
||||
{
|
||||
return _context.Sprints.Any(e => e.id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,13 @@ namespace ScrumTaskboard.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumStatus>>> GetStatus()
|
||||
{
|
||||
return await _context.Status.ToListAsync();
|
||||
IEnumerable<ScrumStatus> filtered = _context.Status;
|
||||
if (HttpContext.Request.Query["title"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumStatus>(s => s.title.Contains(HttpContext.Request.Query["title"].ToString()));
|
||||
}
|
||||
|
||||
return filtered.ToList();
|
||||
}
|
||||
|
||||
// GET: api/status/1
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -21,7 +22,40 @@ namespace ScrumTaskboard.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumTask>>> GetTasks()
|
||||
{
|
||||
return await _context.Tasks.ToListAsync();
|
||||
IEnumerable<ScrumTask> filtered = _context.Tasks;
|
||||
if (HttpContext.Request.Query["title"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumTask>(t => t.title.Contains(HttpContext.Request.Query["title"].ToString()));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["userstoryid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumTask>(t => t.userstoryid == Convert.ToInt32(HttpContext.Request.Query["userstoryid"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["statusid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumTask>(t => t.statusid == Convert.ToInt32(HttpContext.Request.Query["statusid"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["categoryid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumTask>(t => t.categoryid == Convert.ToInt32(HttpContext.Request.Query["categoryid"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["assignedtoid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumTask>(t => t.assignedtoid == Convert.ToInt32(HttpContext.Request.Query["assignedtoid"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["projectid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumTask>(t => t.projectid == Convert.ToInt32(HttpContext.Request.Query["projectid"]));
|
||||
}
|
||||
if (HttpContext.Request.Query["priority"].ToString() != "")
|
||||
{
|
||||
ScrumPrio priority;
|
||||
Enum.TryParse<ScrumPrio>(HttpContext.Request.Query["priority"].ToString(), out priority);
|
||||
filtered = filtered.Where<ScrumTask>(t => t.priority == priority);
|
||||
}
|
||||
|
||||
|
||||
return filtered.ToList();
|
||||
}
|
||||
|
||||
// GET: api/tasks/5
|
||||
|
|
|
@ -21,7 +21,13 @@ namespace ScrumTaskboard.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumUser>>> GetUser()
|
||||
{
|
||||
return await _context.Users.ToListAsync();
|
||||
IEnumerable<ScrumUser> filtered = _context.Users;
|
||||
if (HttpContext.Request.Query["name"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumUser>(u => u.name.Contains(HttpContext.Request.Query["name"].ToString()));
|
||||
}
|
||||
|
||||
return filtered.ToList();
|
||||
}
|
||||
|
||||
// GET: api/sprint/5
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -21,7 +22,40 @@ namespace ScrumTaskboard.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumUserstory>>> GetUserstory()
|
||||
{
|
||||
return await _context.Userstories.ToListAsync();
|
||||
IEnumerable<ScrumUserstory> filtered = _context.Userstories;
|
||||
if (HttpContext.Request.Query["title"].ToString() != "")
|
||||
{
|
||||
filtered = filtered.Where<ScrumUserstory>(t => t.title.Contains(HttpContext.Request.Query["title"].ToString()));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["statusid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumUserstory>(t => t.statusid == Convert.ToInt32(HttpContext.Request.Query["statusid"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["categoryid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumUserstory>(t => t.categoryid == Convert.ToInt32(HttpContext.Request.Query["categoryid"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["createdby"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumUserstory>(t => t.createdbyid == Convert.ToInt32(HttpContext.Request.Query["createdby"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["projectid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumUserstory>(t => t.projectid == Convert.ToInt32(HttpContext.Request.Query["projectid"]));
|
||||
}
|
||||
if (Convert.ToInt32(HttpContext.Request.Query["sprintid"]) != 0)
|
||||
{
|
||||
filtered = filtered.Where<ScrumUserstory>(t => t.sprintid == Convert.ToInt32(HttpContext.Request.Query["sprintid"]));
|
||||
}
|
||||
if (HttpContext.Request.Query["priority"].ToString() != "")
|
||||
{
|
||||
ScrumPrio priority;
|
||||
Enum.TryParse<ScrumPrio>(HttpContext.Request.Query["priority"].ToString(), out priority);
|
||||
filtered = filtered.Where<ScrumUserstory>(t => t.priority == priority);
|
||||
}
|
||||
|
||||
|
||||
return filtered.ToList();
|
||||
}
|
||||
|
||||
// GET: api/userstories/1
|
||||
|
|
Loading…
Reference in New Issue