-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskFunctions.cs
128 lines (88 loc) · 2.77 KB
/
TaskFunctions.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace Todolistappp
{
public class TaskFunctions
{
Data db = new Data();
private readonly List<Task> _tasks;
public TaskFunctions()
{
_tasks = new List<Task>();
_tasks = db.GetDatabase();
}
public void syncToDatabase()
{
db.SetDatabase(_tasks);
}
public void AddTask(string name, DateTime duedate)
{
AddTask(new Task { Name = name, DueDate = duedate });
}
public Task FindById(int id)
{
return _tasks.FirstOrDefault(x => x.Id == id);
}
public void AddTask(params Task[] tasks)
{
var currentId = 0;
if (_tasks.Any())
{
var selectedLastTask = _tasks.OrderByDescending(x => x.Id).FirstOrDefault();
currentId = selectedLastTask.Id;
}
tasks.ToList().ForEach(x =>
{
currentId++;
x.Id = currentId;
});
_tasks.AddRange(tasks);
syncToDatabase();
}
public void UpdateTask(Task outertask)
{
var Tasks = _tasks.Where(Task => Task.Name.ToLower().Contains("a")).ToList();
Tasks.ForEach(Task => {
});
var selectedTask = _tasks.FirstOrDefault(x => x.Id == outertask.Id);
if (selectedTask == null)
{
throw new Exception(string.Format("Cannot find the Task with Id of {0}", outertask.Id));
}
else
{
_tasks.Remove(selectedTask);
var newtask = outertask;
_tasks.Add(newtask);
syncToDatabase();
}
}
public void Delete(int id)
{
var selectedTask = FindById(id);
if (selectedTask == null)
{
throw new Exception(string.Format("Cannot find the Task with Id of {0}", id));
}
_tasks.Remove(selectedTask);
syncToDatabase();
}
public IQueryable<Task> AllTasks()
{
return _tasks.AsQueryable();
}
public string AllTasksString()
{
return string.Join(Environment.NewLine, _tasks.Select(x => x.ToString()));
}
public IQueryable<Task> DueDates(DateTime now)
{
return _tasks.Where(x => x.DueDate < now).AsQueryable();
}
}
}