-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskList.cs
67 lines (57 loc) · 1.45 KB
/
TaskList.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeeManagementSystem
{
internal class TaskList
{
List<Tasks> tasksSet;
public TaskList(List<Tasks> tasks)
{
tasksSet = tasks;
}
public List<Tasks> GetAllTasks() => tasksSet;
public Tasks GetTask(int id)
{
foreach (Tasks task in tasksSet)
{
if (task.Id == id)
{
return task;
}
}
return null;
}
public void AddTask(Tasks tasks)
{
// Generate a new unique ID
int newId = tasksSet.Count > 0 ? tasksSet.Max(t => t.Id) + 1 : 1;
tasks.Id = newId;
tasksSet.Add(tasks);
}
public bool RemoveTask(int id)
{
Tasks taskToRemove = null;
foreach (Tasks task in tasksSet)
{
if (task.Id == id)
{
taskToRemove = task;
break;
}
}
if (taskToRemove != null)
{
tasksSet.Remove(taskToRemove);
return true;
}
else
{
Console.WriteLine($"Task with ID {id} not found.");
return false;
}
}
}
}