Added filters for all get-all endpoints
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user