Merge branch 'comments/task-context' into comments/merge

This commit is contained in:
2020-07-14 18:03:33 +02:00
8 changed files with 219 additions and 158 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -7,8 +7,8 @@ using Microsoft.EntityFrameworkCore;
namespace ScrumTaskboard.Controllers
{
/// <summary>
/// This is a controller of Tasks class includes all API's related to the Tasks.
/// <summary>
/// This is a controller of Tasks class includes all API's related to the Tasks.
/// </summary>
[Route("[controller]")]
[ApiController]
@@ -16,53 +16,53 @@ namespace ScrumTaskboard.Controllers
{
private readonly TaskContext _context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="context"></param>
public TasksController(TaskContext context)
{
_context = context;
}
// GET: api/tasks
}
// GET: api/tasks
#nullable enable
[HttpGet]
public async Task<ActionResult<IEnumerable<ScrumTask>>> GetTasks([FromQuery]string? title, [FromQuery]int? userstoryid, [FromQuery]int? statusid, [FromQuery]int? assignedtoid, [FromQuery]int? projectid, [FromQuery]ScrumPrio? priority)
{
var filtered = _context.Tasks.AsQueryable();
if (title != null)
{
filtered = filtered.Where<ScrumTask>(t => t.title.Contains(title));
if (title != null)
{
filtered = filtered.Where<ScrumTask>(t => t.Title.Contains(title));
}
if (userstoryid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.userstoryid == userstoryid);
if (userstoryid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.UserstoryId == userstoryid);
}
if (statusid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.statusid == statusid);
if (statusid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.StatusId == statusid);
}
if (assignedtoid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.assignedtoid == assignedtoid);
if (assignedtoid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.AssignedToId == assignedtoid);
}
if (projectid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.projectid == projectid);
if (projectid != null)
{
filtered = filtered.Where<ScrumTask>(t => t.ProjectId == projectid);
}
if (priority != null)
{
filtered = filtered.Where<ScrumTask>(t => t.priority == priority);
}
if (priority != null)
{
filtered = filtered.Where<ScrumTask>(t => t.Priority == priority);
}
return await filtered.ToListAsync();
}
}
#nullable disable
// GET: api/tasks/5
// GET: api/tasks/5
[HttpGet("{id}")]
public async Task<ActionResult<ScrumTask>> GetTask(int id)
{
@@ -144,7 +144,7 @@ namespace ScrumTaskboard.Controllers
/// </summary>
private bool TaskExists(int id)
{
return _context.Tasks.Any(e => e.id == id);
return _context.Tasks.Any(e => e.Id == id);
}
}
}