Repository navigation
Expand file tree
/
Copy pathSQLiteManager.cs
More file actions
59 lines (50 loc) · 1.68 KB
/
Copy pathSQLiteManager.cs
File metadata and controls
59 lines (50 loc) · 1.68 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
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab9DatabaseConnection
{
internal class SQLiteManager
{
// Class used to manage/access the SQLite database
private SQLiteConnection database;
public SQLiteManager()
{
// Creates a connection using the pre-specifed path in the Constants class
database = new SQLiteConnection(Constants.DatabasePath);
// Creates a Courses table
database.CreateTable<Course>();
}
// Add a course to the course table
public void AddCourse(Course course)
{
database.Insert(course);
}
// Get all courses and add them to a list, then display their details in the console
public void DisplayAllCourses()
{
List<Course> allCourses = database.Table<Course>().ToList();
foreach (Course course in allCourses)
{
Console.WriteLine(course);
}
}
// Find a Course object/row by its Id value
public Course GetCourseById(int id)
{
return database.Table<Course>().Where(c => c.CourseId == id).FirstOrDefault();
}
// Change the columns/attributes of a specified object in the database
public void UpdateCourse(Course course)
{
database.Update(course);
}
// Remove a row from the database entirely
public void DeleteCourse(int id)
{
database.Delete<Course>(id);
}
}
}