Skip to content

Commit

Permalink
SchoolManagerModel 1.1
Browse files Browse the repository at this point in the history
Better namespace structure, SchoolDbContextBase
  • Loading branch information
TheKornelM authored Nov 9, 2024
2 parents 1d1e660 + 01f837b commit 8045ee8
Show file tree
Hide file tree
Showing 46 changed files with 430 additions and 350 deletions.
50 changes: 50 additions & 0 deletions README.md
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).
19 changes: 0 additions & 19 deletions SchoolManagerModel/AssignedSubject.cs

This file was deleted.

19 changes: 0 additions & 19 deletions SchoolManagerModel/ClassExistsException.cs

This file was deleted.

18 changes: 18 additions & 0 deletions SchoolManagerModel/Entities/AssignedSubject.cs
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; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SchoolManagerModel;
namespace SchoolManagerModel.Entities;

public class Class
{
Expand Down
17 changes: 17 additions & 0 deletions SchoolManagerModel/Entities/Lesson.cs
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; }
}
19 changes: 19 additions & 0 deletions SchoolManagerModel/Entities/Mark.cs
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;
}
8 changes: 8 additions & 0 deletions SchoolManagerModel/Entities/Role.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SchoolManagerModel.Entities;

public enum Role
{
Student,
Teacher,
Administrator
}
14 changes: 14 additions & 0 deletions SchoolManagerModel/Entities/RoleRecord.cs
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;
}
28 changes: 28 additions & 0 deletions SchoolManagerModel/Entities/Subject.cs
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; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SchoolManagerModel.UserModel;
namespace SchoolManagerModel.Entities.UserModel;

public class Admin
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SchoolManagerModel.UserModel;
namespace SchoolManagerModel.Entities.UserModel;

public class Student
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SchoolManagerModel.UserModel;
namespace SchoolManagerModel.Entities.UserModel;

public class Teacher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SchoolManagerModel.UserModel;
namespace SchoolManagerModel.Entities.UserModel;

public class User
{
Expand Down
17 changes: 17 additions & 0 deletions SchoolManagerModel/Exceptions/ClassExistsException.cs
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)
{
}
}
16 changes: 0 additions & 16 deletions SchoolManagerModel/Lesson.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SchoolManagerModel.Persistence;
using SchoolManagerModel.UserModel;
using SchoolManagerModel.Entities;
using SchoolManagerModel.Entities.UserModel;
using SchoolManagerModel.Exceptions;
using SchoolManagerModel.Persistence;

namespace SchoolManagerModel;
namespace SchoolManagerModel.Managers;

public class ClassManager(IAsyncClassDataHandler dataHandler)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using SchoolManagerModel.Persistence;
using SchoolManagerModel.Utils;

namespace SchoolManagerModel;
namespace SchoolManagerModel.Managers;

public class LoginManager(IAsyncUserDataHandler schoolData)
{
Expand All @@ -11,7 +12,7 @@ public async Task LoginAsync(string username, string password)
?? throw new Exception("User not found");


string hashedPassword = HashStringMD5.GetHashedString(password);
string hashedPassword = HashStringMd5.GetHashedString(password);

if (hashedPassword != result.Password)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using SchoolManagerModel.Persistence;
using SchoolManagerModel.UserModel;
using SchoolManagerModel.Entities;
using SchoolManagerModel.Entities.UserModel;
using SchoolManagerModel.Persistence;

namespace SchoolManagerModel;
namespace SchoolManagerModel.Managers;

public class SubjectManager(IAsyncSubjectDataHandler dataHandler)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using SchoolManagerModel.Persistence;
using SchoolManagerModel.UserModel;
using SchoolManagerModel.Entities;
using SchoolManagerModel.Entities.UserModel;
using SchoolManagerModel.Persistence;

namespace SchoolManagerModel;
namespace SchoolManagerModel.Managers;

internal class TeacherManager(IAsyncTeacherDataHandler dataHandler)
public class TeacherManager(IAsyncTeacherDataHandler dataHandler)
{
private readonly IAsyncTeacherDataHandler _dataHandler = dataHandler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SchoolManagerModel.Persistence;
using SchoolManagerModel.UserModel;
using SchoolManagerModel.Entities;
using SchoolManagerModel.Entities.UserModel;
using SchoolManagerModel.Persistence;
using SchoolManagerModel.Utils;

namespace SchoolManagerModel;
namespace SchoolManagerModel.Managers;

public class UserManager(IAsyncUserDataHandler dataHandler)
{
Expand Down Expand Up @@ -71,7 +73,7 @@ public async Task RegisterUserAsync(User user)
throw new Exception("Email already registered");
}

user.Password = HashStringMD5.GetHashedString(user.Password);
user.Password = HashStringMd5.GetHashedString(user.Password);

await _dataHandler.AddUserAsync(user);
}
Expand Down
19 changes: 0 additions & 19 deletions SchoolManagerModel/Mark.cs

This file was deleted.

Loading

0 comments on commit 8045ee8

Please sign in to comment.