Added filters for all get-all endpoints

This commit is contained in:
2020-06-18 15:10:42 +02:00
parent 48d5622c0f
commit 8a26b957aa
7 changed files with 219 additions and 92 deletions

View File

@@ -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