-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.cs
48 lines (40 loc) · 1.21 KB
/
Database.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
using System;
using System.Collections.Generic;
namespace MemoriesApp
// Represents in-memory database for journal
{
class Database
{
// Journal memories
private List<Memory> memories;
// Initializes instance
public Database()
{
memories = new List<Memory>();
}
// Adds a new memory
public void AddMemory(DateTime occurs, string text)
{
memories.Add(new Memory(occurs, text));
}
public List<Memory> FindMemories(DateTime date, bool byTime)
{
List<Memory> found = new List<Memory>();
foreach (Memory memory in memories)
{
if (((byTime) && (memory.Occurs == date)) // by time and date
||
((!byTime) && (memory.Occurs.Date == date.Date))) // by date only
found.Add(memory);
}
return found;
}
// Removes memories occurring on specified date
public void DeleteMemories(DateTime date)
{
List<Memory> found = FindMemories(date, true);
foreach (Memory memory in found)
memories.Remove(memory);
}
}
}