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

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

View File

@ -34,15 +34,15 @@ namespace ScrumTaskboard.Controllers
if (title != null)
{
filtered = filtered.Where<ScrumCategory>(c => c.title.Contains(title));
filtered = filtered.Where<ScrumCategory>(c => c.Title.Contains(title));
}
if (projectid != null)
{
filtered = filtered.Where<ScrumCategory>(c => c.projectid == projectid);
filtered = filtered.Where<ScrumCategory>(c => c.ProjectId == projectid);
}
if (color != null)
{
filtered = filtered.Where<ScrumCategory>(c => c.color == color);
filtered = filtered.Where<ScrumCategory>(c => c.Color == color);
}
@ -132,7 +132,7 @@ namespace ScrumTaskboard.Controllers
/// </summary>
private bool CategoryExists(int id)
{
return _context.Categories.Any(e => e.id == id);
return _context.Categories.Any(e => e.Id == id);
}
}
}

View File

@ -34,11 +34,11 @@ namespace ScrumTaskboard.Controllers
if (title != null)
{
filtered = filtered.Where<ScrumProject>(t => t.title.Contains(title));
filtered = filtered.Where<ScrumProject>(t => t.Title.Contains(title));
}
if (isprivate != null)
{
filtered = filtered.Where<ScrumProject>(t => t.isprivate == isprivate);
filtered = filtered.Where<ScrumProject>(t => t.IsPrivate == isprivate);
}
return await filtered.ToListAsync();
@ -49,14 +49,14 @@ namespace ScrumTaskboard.Controllers
[HttpGet("{id}")]
public async Task<ActionResult<ScrumProject>> GetProjects(int id)
{
var Project = await _context.Projects.FindAsync(id);
var project = await _context.Projects.FindAsync(id);
if (Project == null)
if (project == null)
{
return NotFound();
}
return Project;
return project;
}
// PUT: api/Project/5
@ -127,7 +127,7 @@ namespace ScrumTaskboard.Controllers
/// </summary>
private bool ProjectExists(int id)
{
return _context.Projects.Any(e => e.id == id);
return _context.Projects.Any(e => e.Id == id);
}
}
}

View File

@ -1,55 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace ScrumTaskboard.Controllers
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace ScrumTaskboard.Controllers
{
/// <summary>
/// This is a controller of Sprints class includes all API's related to the Sprints.
/// </summary>
[Route("[controller]")]
[ApiController]
public class SprintsController : ControllerBase
{
private readonly TaskContext _context;
/// </summary>
[Route("[controller]")]
[ApiController]
public class SprintsController : ControllerBase
{
private readonly TaskContext _context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="context"></param>
public SprintsController(TaskContext context)
{
_context = context;
/// <param name="context"></param>
public SprintsController(TaskContext context)
{
_context = context;
}
// GET: api/sprint
#nullable enable
[HttpGet]
public async Task<ActionResult<IEnumerable<ScrumSprint>>> GetSprint([FromQuery]string? title, [FromQuery]int? projectid, [FromQuery]DateTime? startDate, [FromQuery]DateTime? endDate)
{
var filtered = _context.Sprints.AsQueryable();
if (title != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.title.Contains(title));
}
if (projectid != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.projectid == projectid);
}
#nullable enable
[HttpGet]
public async Task<ActionResult<IEnumerable<ScrumSprint>>> GetSprint([FromQuery]string? title, [FromQuery]int? projectid, [FromQuery]DateTime? startDate, [FromQuery]DateTime? endDate)
{
var filtered = _context.Sprints.AsQueryable();
if (title != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.Title.Contains(title));
}
if (projectid != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.ProjectId == projectid);
}
if (startDate != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.startDate == startDate);
filtered = filtered.Where<ScrumSprint>(s => s.StartDate == startDate);
}
if (endDate != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.endDate == endDate);
}
return await filtered.ToListAsync();
{
filtered = filtered.Where<ScrumSprint>(s => s.EndDate == endDate);
}
return await filtered.ToListAsync();
}
#nullable disable
@ -57,14 +57,14 @@ namespace ScrumTaskboard.Controllers
[HttpGet("{id}")]
public async Task<ActionResult<ScrumSprint>> GetSprint(int id)
{
var Sprint = await _context.Sprints.FindAsync(id);
var sprint = await _context.Sprints.FindAsync(id);
if (Sprint == null)
if (sprint == null)
{
return NotFound();
}
return Sprint;
return sprint;
}
// PUT: api/sprint/5
@ -130,12 +130,12 @@ namespace ScrumTaskboard.Controllers
return scrumSprint;
}
/// <summary>
/// Checks whether a sprint with the specified ID already exists.
/// </summary>
/// <summary>
/// Checks whether a sprint with the specified ID already exists.
/// </summary>
private bool SprintExists(int id)
{
return _context.Sprints.Any(e => e.id == id);
return _context.Sprints.Any(e => e.Id == id);
}
}
}
}
}

View File

@ -33,7 +33,7 @@ namespace ScrumTaskboard.Controllers
if (title != null)
{
filtered = filtered.Where<ScrumStatus>(s => s.title.Contains(title));
filtered = filtered.Where<ScrumStatus>(s => s.Title.Contains(title));
}
return await filtered.ToListAsync();
@ -122,7 +122,7 @@ namespace ScrumTaskboard.Controllers
/// </summary>
private bool StatusExists(int id)
{
return _context.Status.Any(e => e.id == id);
return _context.Status.Any(e => e.Id == id);
}
}
}

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);
}
}
}

View File

@ -32,7 +32,7 @@ namespace ScrumTaskboard.Controllers
var filtered = _context.Users.AsQueryable();
if (name != null)
{
filtered = filtered.Where<ScrumUser>(u => u.name.Contains(name));
filtered = filtered.Where<ScrumUser>(u => u.Name.Contains(name));
}
return await filtered.ToListAsync();
@ -43,14 +43,14 @@ namespace ScrumTaskboard.Controllers
[HttpGet("{id}")]
public async Task<ActionResult<ScrumUser>> GetUser(int id)
{
var User = await _context.Users.FindAsync(id);
var user = await _context.Users.FindAsync(id);
if (User == null)
if (user == null)
{
return NotFound();
}
return User;
return user;
}
// PUT: api/sprint/5
@ -121,7 +121,7 @@ namespace ScrumTaskboard.Controllers
/// </summary>
private bool UserExists(int id)
{
return _context.Users.Any(e => e.id == id);
return _context.Users.Any(e => e.Id == id);
}
}
}

View File

@ -34,31 +34,31 @@ namespace ScrumTaskboard.Controllers
if (title != null)
{
filtered = filtered.Where<ScrumUserstory>(t => t.title.Contains(title));
filtered = filtered.Where<ScrumUserstory>(t => t.Title.Contains(title));
}
if (statusid != null)
{
filtered = filtered.Where<ScrumUserstory>(t => t.statusid == statusid);
filtered = filtered.Where<ScrumUserstory>(t => t.StatusId == statusid);
}
if (categoryid != null)
{
filtered = filtered.Where<ScrumUserstory>(t => t.categoryid == categoryid);
filtered = filtered.Where<ScrumUserstory>(t => t.CategoryId == categoryid);
}
if (createdbyid != null)
{
filtered = filtered.Where<ScrumUserstory>(t => t.createdbyid == createdbyid);
filtered = filtered.Where<ScrumUserstory>(t => t.CreatedById == createdbyid);
}
if (projectid != null)
{
filtered = filtered.Where<ScrumUserstory>(t => t.projectid == projectid);
filtered = filtered.Where<ScrumUserstory>(t => t.ProjectId == projectid);
}
if (sprintid != null)
{
filtered = filtered.Where<ScrumUserstory>(t => t.sprintid == sprintid);
filtered = filtered.Where<ScrumUserstory>(t => t.SprintId == sprintid);
}
if (priority != null)
{
filtered = filtered.Where<ScrumUserstory>(t => t.priority == priority);
filtered = filtered.Where<ScrumUserstory>(t => t.Priority == priority);
}
@ -148,7 +148,7 @@ namespace ScrumTaskboard.Controllers
/// </summary>
private bool UserstoryExists(int id)
{
return _context.Userstories.Any(e => e.id == id);
return _context.Userstories.Any(e => e.Id == id);
}
}
}

View File

@ -4,6 +4,13 @@ using System.Runtime.Serialization;
namespace ScrumTaskboard
{
/// <summary>
/// Provides access to the database via the Entity Framework Core.
/// </summary>
/// <remarks>
/// Each <see cref="DbSet{TEntity}"/> property represents a table.
/// Tables can be queried and updated via the context class.
/// </remarks>
public class TaskContext : DbContext
{
public DbSet<ScrumTask> Tasks { get; set; }
@ -14,106 +21,160 @@ namespace ScrumTaskboard
public DbSet<ScrumProject> Projects { get; set; }
public DbSet<ScrumUser> Users { get; set; }
/// <summary>
/// Creates a new <see cref="TaskContext"/> instance with default options.
/// </summary>
public TaskContext() { }
/// <summary>
/// Creates a new <see cref="TaskContext"/> instance with the given options.
/// </summary>
public TaskContext(DbContextOptions<TaskContext> options) : base(options) { }
}
/// <summary>
/// Represents a task in an agile work process.
/// </summary>
/// <remarks>
/// A task is a small piece of work, associated with a larger userstory.
/// </remarks>
public class ScrumTask
{
public int id { get; set; }
public string title { get; set; }
public string content { get; set; }
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int? statusid { get; set; }
public ScrumStatus status { get; set; }
public int? StatusId { get; set; }
public ScrumStatus Status { get; set; }
public int? assignedtoid { get; set; }
public ScrumUser assignedto { get; set; }
public int? AssignedToId { get; set; }
public ScrumUser AssignedTo { get; set; }
public int? projectid { get; set; }
public ScrumProject project { get; set; }
public int? ProjectId { get; set; }
public ScrumProject Project { get; set; }
public int? userstoryid { get; set; }
public ScrumUserstory userstory { get; set; }
public int? UserstoryId { get; set; }
public ScrumUserstory Userstory { get; set; }
public ScrumPrio priority { get; set; }
public ScrumPrio Priority { get; set; }
}
/// <summary>
/// Represents a userstory in an agile work process.
/// </summary>
/// <remarks>
/// A userstory is a piece of work that can be done in one sprint.
/// It can be further divided into multiple tasks.
/// </remarks>
public class ScrumUserstory
{
public int id { get; set; }
public string title { get; set; }
public string content { get; set; }
public ScrumPrio priority { get; set; }
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public ScrumPrio Priority { get; set; }
public int? statusid { get; set; }
public ScrumStatus status { get; set; }
public int? StatusId { get; set; }
public ScrumStatus Status { get; set; }
public int? categoryid { get; set; }
public ScrumCategory category { get; set; }
public int? CategoryId { get; set; }
public ScrumCategory Category { get; set; }
public int? createdbyid { get; set; }
public ScrumUser createdby { get; set; }
public int? CreatedById { get; set; }
public ScrumUser CreatedBy { get; set; }
public int? projectid { get; set; }
public ScrumProject project { get; set; }
public int? ProjectId { get; set; }
public ScrumProject Project { get; set; }
public int? sprintid { get; set; }
public ScrumSprint sprint { get; set; }
public int? SprintId { get; set; }
public ScrumSprint Sprint { get; set; }
}
/// <summary>
/// Represents a category of userstories.
/// </summary>
/// <remarks>
/// Every userstory can optionally be associated with a single category.
/// This can be helpful to organize work in larger teams.
/// </remarks>
public class ScrumCategory
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
public string color { get; set; }
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Color { get; set; }
public int? projectid { get; set; }
public ScrumProject project { get; set; }
public int? ProjectId { get; set; }
public ScrumProject Project { get; set; }
}
/// <summary>
/// Represents an agile sprint.
/// </summary>
/// <remarks>
/// A sprint is typically one to four weeks long.
/// Userstories are typically started and completed
/// during one sprint.
/// </remarks>
public class ScrumSprint
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? projectid { get; set; }
public ScrumProject project { get; set; }
public int? ProjectId { get; set; }
public ScrumProject Project { get; set; }
}
/// <summary>
/// Represents the status of a task or userstory.
/// </summary>
/// <remarks>
/// Classic status are "Backlog", "In Progress" and "Done", but
/// teams can create others to fit their individual workflow.
/// </remarks>
public class ScrumStatus
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
/// <summary>
/// Represents a project that the team works on.
/// </summary>
/// <remarks>
/// Userstories and sprints can be categorized into projects,
/// to help organization for larger teams.
/// </remarks>
public class ScrumProject
{
public int id { get; set; }
public string title { get; set; }
public bool isprivate { get; set; }
public int Id { get; set; }
public string Title { get; set; }
public bool IsPrivate { get; set; }
}
/// <summary>
/// Represents a team member that can work on userstories.
/// </summary>
/// <remarks>
/// This allows teams to track who is working on a userstory
/// at a given time.
/// </remarks>
public class ScrumUser
{
public int id { get; set; }
public string name { get; set; }
public int Id { get; set; }
public string Name { get; set; }
}
public enum ScrumPrio
{
[EnumMember(Value = "low")]
low,
Low,
[EnumMember(Value = "medium")]
medium,
Medium,
[EnumMember(Value = "high")]
high
High
}
}