-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better namespace structure, SchoolDbContextBase
- Loading branch information
Showing
46 changed files
with
430 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# SchoolManagerModel | ||
|
||
Created by Kornél Makári | ||
|
||
## Project Structure | ||
There are 5 namespaces: | ||
- **SchoolManagerModel.Entities**: Objects and entities stored in the database. | ||
- **SchoolManagerModel.Exceptions**: Implemented exceptions. | ||
- **SchoolManagerModel.Managers**: Business logic with persistence through interfaces. | ||
- **SchoolManagerModel.Persistence**: Data storage. | ||
|
||
## Model | ||
|
||
### Manager Classes | ||
There are 5 manager classes that contain the business logic: | ||
|
||
- `ClassManager` | ||
- `LoginManager` | ||
- `SubjectManager` | ||
- `TeacherManager` | ||
- `UserManager` | ||
|
||
## Persistence | ||
Entity Framework is used for data storage, but you can easily use any other technology. | ||
|
||
### Data Storage Interfaces | ||
Manager classes are not dependent on Entity Framework. There are 4 handler interfaces: | ||
- `IAsyncClassDataHandler` | ||
- `IAsyncSubjectDataHandler` | ||
- `IAsyncTeacherDataHandler` | ||
- `IAsyncUserDataHandler` | ||
|
||
If you want to use, for example, Dapper, you need to implement these interfaces. | ||
|
||
### Entity Framework | ||
|
||
Entity Framework-specific classes use these interfaces. | ||
|
||
Entity Framework classes: | ||
- `ClassDatabase` | ||
- `SubjectDatabase` | ||
- `TeacherDatabase` | ||
- `UserDatabase` | ||
|
||
## Database | ||
Persistence is implemented with a local SQLite database. If you want to use another database engine, you need to install the engine-specific NuGet package and create a class based on `SchoolDbContextBase`. | ||
|
||
`SchoolDbContextBase` is an abstract class, and you need to override two methods: | ||
- `OnConfiguring(DbContextOptionsBuilder optionsBuilder)`: To configure the database with the specific engine. | ||
- `OnModelCreating(ModelBuilder modelBuilder)`: To seed data (e.g., create accounts). |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using SchoolManagerModel.Entities.UserModel; | ||
|
||
namespace SchoolManagerModel.Entities; | ||
|
||
public class AssignedSubject | ||
{ | ||
[Key] | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public int Id { get; set; } | ||
|
||
public required Subject Subject { get; set; } | ||
public required Student Student { get; set; } | ||
public List<Mark>? Marks { get; set; } | ||
public bool GotGrade { get; set; } | ||
public int? Mark { get; set; } | ||
} |
2 changes: 1 addition & 1 deletion
2
SchoolManagerModel/Class.cs → SchoolManagerModel/Entities/Class.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using SchoolManagerModel.Entities.UserModel; | ||
|
||
namespace SchoolManagerModel.Entities; | ||
|
||
public class Lesson | ||
{ | ||
[Key] | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public int Id { get; set; } | ||
|
||
public required string Name { get; set; } | ||
public required Teacher TeacherId { get; set; } | ||
public DateTime Beginning { get; set; } | ||
public DateTime Ending { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using SchoolManagerModel.Entities.UserModel; | ||
|
||
namespace SchoolManagerModel.Entities; | ||
|
||
public class Mark | ||
{ | ||
[Key] | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public int Id { get; set; } | ||
|
||
public int Grade { get; set; } | ||
public required Student Student { get; set; } | ||
public required Subject Subject { get; set; } | ||
|
||
public required DateTime SubmitDate { get; set; } | ||
public string Notes { get; set; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SchoolManagerModel.Entities; | ||
|
||
public enum Role | ||
{ | ||
Student, | ||
Teacher, | ||
Administrator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace SchoolManagerModel.Entities; | ||
|
||
public class RoleRecord(int userId, int roleId) | ||
{ | ||
[Key] | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public int Id { get; set; } | ||
|
||
public int UserId { get; set; } = userId; | ||
public int RoleId { get; set; } = roleId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using SchoolManagerModel.Entities.UserModel; | ||
|
||
namespace SchoolManagerModel.Entities; | ||
|
||
public class Subject | ||
{ | ||
// Required for Entity Framework | ||
public Subject() | ||
{ | ||
} | ||
|
||
public Subject(string name, Class @class, Teacher teacher) | ||
{ | ||
Name = name; | ||
Class = @class; | ||
Teacher = teacher; | ||
} | ||
|
||
[Key] | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||
public int Id { get; set; } | ||
|
||
public required string Name { get; set; } | ||
public required Class Class { get; set; } | ||
public required Teacher Teacher { get; set; } | ||
} |
2 changes: 1 addition & 1 deletion
2
SchoolManagerModel/UserModel/Admin.cs → ...lManagerModel/Entities/UserModel/Admin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
SchoolManagerModel/UserModel/Student.cs → ...anagerModel/Entities/UserModel/Student.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
SchoolManagerModel/UserModel/Teacher.cs → ...anagerModel/Entities/UserModel/Teacher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
SchoolManagerModel/UserModel/User.cs → ...olManagerModel/Entities/UserModel/User.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace SchoolManagerModel.Exceptions; | ||
|
||
[Serializable] | ||
public class ClassExistsException : Exception | ||
{ | ||
public ClassExistsException() | ||
{ | ||
} | ||
|
||
public ClassExistsException(string? message) : base(message) | ||
{ | ||
} | ||
|
||
public ClassExistsException(string? message, Exception? innerException) : base(message, innerException) | ||
{ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
8 changes: 5 additions & 3 deletions
8
SchoolManagerModel/ClassManager.cs → SchoolManagerModel/Managers/ClassManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
SchoolManagerModel/SubjectManager.cs → ...olManagerModel/Managers/SubjectManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
SchoolManagerModel/TeacherManager.cs → ...olManagerModel/Managers/TeacherManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.