forked from OpenClassrooms-Student-Center/DotNET_Developer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoModel.cs
More file actions
50 lines (39 loc) · 1.19 KB
/
Copy pathTodoModel.cs
File metadata and controls
50 lines (39 loc) · 1.19 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Model
{
public class TodoModel
{
private readonly List<TodoTask> _tasks;
public IEnumerable<TodoTask> Tasks { get; set; }
public TodoModel()
{
}
public TodoTask CreateTask(string name)
{
var newTask = new TodoTask(name);
InternalAddTask(newTask);
return newTask;
}
public TodoTask GetTask(string name)
{
return _tasks.FirstOrDefault(task => task.Name == name);
}
public IEnumerable<TodoTask> GetDoneTasks()
{
var doneTasks = new List<TodoTask>();
for (int currentTask = 0; currentTask < _tasks.Count; currentTask++)
{
if (_tasks[currentTask].Done)
doneTasks.Add(_tasks[currentTask]);
}
return doneTasks;
}
private void InternalAddTask(TodoTask newTask)
{
if (GetTask(newTask.Name) != null) throw new InvalidOperationException($"Task '{newTask.Name}' already exists");
_tasks.Add(newTask);
}
}
}