-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskService.cs
More file actions
71 lines (64 loc) · 1.65 KB
/
TaskService.cs
File metadata and controls
71 lines (64 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace TaskFlow;
/// <summary>
/// Provides services for managing tasks.
/// </summary>
public class TaskService
{
/// <summary>
/// Gets or sets the list of tasks.
/// </summary>
public List<Task> Tasks { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="TaskService"/> class.
/// </summary>
public TaskService()
{
Tasks = new List<Task>();
}
/// <summary>
/// Adds a new task to the service.
/// </summary>
/// <param name="title">The title of the task.</param>
/// <param name="description">The description of the task.</param>
public void AddTask(string title, string description)
{
Task task = new Task(title: title, description: description);
Tasks.Add(task);
}
/// <summary>
/// Removes a task from the service.
/// </summary>
/// <param name="task">The task to remove.</param>
/// <returns>The removed task if found; otherwise, null.</returns>
public Task? DeleteTask(Task task)
{
if (Tasks.Remove(task))
{
return task;
}
return null;
}
/// <summary>
/// Marks a task as completed.
/// </summary>
/// <param name="task">The task to complete.</param>
public void CompleteTask(Task task)
{
foreach (var t in Tasks)
{
if (t == task)
{
t.Status = true;
break;
}
}
}
/// <summary>
/// Retrieves all tasks.
/// </summary>
/// <returns>A list of all tasks.</returns>
public List<Task> GetAllTasks()
{
return Tasks;
}
}