Skip to content

Commit

Permalink
Merge pull request #11 from TheKornelM/dev
Browse files Browse the repository at this point in the history
Filter and show users, class diagrams
  • Loading branch information
TheKornelM authored Nov 28, 2024
2 parents 9f25f7a + 7f3b240 commit b76cda5
Show file tree
Hide file tree
Showing 19 changed files with 610 additions and 40 deletions.
27 changes: 27 additions & 0 deletions SchoolManagerModel/DTOs/UserDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using SchoolManagerModel.Utils;

namespace SchoolManagerModel.DTOs;
public class UserDto
{
public string Username { get; set; }
public string Email { get; set; }

public string FirstName { get; set; }

public string LastName { get; set; }

public string Name => CultureUtils.GetFullName(FirstName, LastName);

public UserDto()
{

}

public UserDto(string username, string email, string firstName, string lastName)
{
Username = username;
Email = email;
FirstName = firstName;
LastName = lastName;
}
}
5 changes: 2 additions & 3 deletions SchoolManagerModel/Entities/AssignedSubject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using SchoolManagerModel.Entities.UserModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SchoolManagerModel.Entities.UserModel;

namespace SchoolManagerModel.Entities;

Expand All @@ -12,7 +12,6 @@ public class AssignedSubject

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; }
}
7 changes: 5 additions & 2 deletions SchoolManagerModel/Entities/Mark.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using SchoolManagerModel.Entities.UserModel;
using SchoolManagerModel.Utils;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SchoolManagerModel.Entities.UserModel;

namespace SchoolManagerModel.Entities;

Expand All @@ -16,4 +17,6 @@ public class Mark

public required DateTime SubmitDate { get; set; }
public string Notes { get; set; } = string.Empty;

public string Date => CultureUtils.GetTimeString(SubmitDate);
}
2 changes: 1 addition & 1 deletion SchoolManagerModel/Entities/UserModel/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class User

public string LastName { get; set; }

public string Name => FullName.Get(FirstName, LastName);
public string Name => CultureUtils.GetFullName(FirstName, LastName);

public User()
{
Expand Down
88 changes: 88 additions & 0 deletions SchoolManagerModel/EntitiesClassDiagram.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1" MembersFormat="FullSignature">
<Class Name="SchoolManagerModel.Exceptions.ClassExistsException">
<Position X="10.5" Y="6" Width="4.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Exceptions\ClassExistsException.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.UserModel.Admin">
<Position X="2.75" Y="3.5" Width="1.75" />
<TypeIdentifier>
<HashCode>AAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Entities\UserModel\Admin.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.UserModel.Student">
<Position X="7.25" Y="9.25" Width="3.25" />
<TypeIdentifier>
<HashCode>AAADAEAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Entities\UserModel\Student.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.UserModel.Teacher">
<Position X="1.75" Y="5.25" Width="1.75" />
<TypeIdentifier>
<HashCode>AAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Entities\UserModel\Teacher.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.UserModel.User">
<Position X="4.25" Y="6" Width="5.5" />
<TypeIdentifier>
<HashCode>AAACAEAAACAAAAAAAQAAAAQAAAAAAAACAAAAAAAAAAg=</HashCode>
<FileName>Entities\UserModel\User.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.AssignedSubject">
<Position X="5" Y="3.25" Width="2.25" />
<TypeIdentifier>
<HashCode>AAACAABAQAAAAAAAAIAAAAAAAAAAAAAAAACAAAAAAAA=</HashCode>
<FileName>Entities\AssignedSubject.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.Class">
<Position X="4.25" Y="9.25" Width="2.5" />
<TypeIdentifier>
<HashCode>AAACAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Entities\Class.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.Lesson">
<Position X="11.75" Y="3.5" Width="2.5" />
<TypeIdentifier>
<HashCode>AAACAAAAAAAAAAAAAAAACAQAAAAAAAAABAAAAAAAAAI=</HashCode>
<FileName>Entities\Lesson.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.Mark">
<Position X="11" Y="8.25" Width="2.5" />
<TypeIdentifier>
<HashCode>AAAiAABAQAAAAAAAAIAAAAAAAAAAAAABAAAAAAEAAAA=</HashCode>
<FileName>Entities\Mark.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.RoleRecord">
<Position X="1.75" Y="8.75" Width="1.75" />
<TypeIdentifier>
<HashCode>AAACAAIAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Entities\RoleRecord.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Entities.Subject">
<Position X="7.75" Y="3" Width="3.5" />
<TypeIdentifier>
<HashCode>AAECAAAAAAAAAAAAAAIAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Entities\Subject.cs</FileName>
</TypeIdentifier>
</Class>
<Enum Name="SchoolManagerModel.Entities.Role">
<Position X="2" Y="7" Width="1.5" />
<TypeIdentifier>
<HashCode>AAEAAAAAQAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Entities\Role.cs</FileName>
</TypeIdentifier>
</Enum>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
6 changes: 3 additions & 3 deletions SchoolManagerModel/Managers/SubjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace SchoolManagerModel.Managers;

public class SubjectManager(IAsyncSubjectDataHandler dataHandler)
{
public async Task AddSubjectMarkAsync(Student student, Subject subject, Mark mark)
public async Task AddSubjectMarkAsync(Mark mark)
{
await CheckAssignedSubjectToStudentAsync(student, subject);
await CheckAssignedSubjectToStudentAsync(mark.Student, mark.Subject);
await dataHandler.AddMarkAsync(mark);
}

Expand Down Expand Up @@ -40,7 +40,7 @@ public async Task<List<Student>> GetSubjectStudentsAsync(Subject subject)
return await dataHandler.GetSubjectStudentsAsync(subject);
}

public async Task<List<Mark>> GetStudentMarkAsync(Student student)
public async Task<List<Mark>> GetStudentMarksAsync(Student student)
{
return await dataHandler.GetStudentMarksAsync(student);
}
Expand Down
10 changes: 8 additions & 2 deletions SchoolManagerModel/Managers/UserManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SchoolManagerModel.Entities;
using SchoolManagerModel.DTOs;
using SchoolManagerModel.Entities;
using SchoolManagerModel.Entities.UserModel;
using SchoolManagerModel.Persistence;
using SchoolManagerModel.Utils;
Expand Down Expand Up @@ -87,7 +88,7 @@ public async Task RegisterUserAsync(User user)
return await dataHandler.GetUserByUsernameAsync(username);
}

public async Task<List<User>> GetUsersAsync()
public async Task<List<UserDto>> GetUsersAsync()
{
return await dataHandler.GetUsersAsync();
}
Expand All @@ -97,5 +98,10 @@ public async Task<Student> GetStudentByUserAsync(User user)
var result = await dataHandler.GetStudentByUserAsync(user);
return result ?? throw new Exception("Student not found");
}

public async Task<List<UserDto>> FilterUsersAsync(string? username = null, string? firstName = null, string? lastName = null, string? email = null)
{
return await dataHandler.FilterUsersAsync(username, firstName, lastName, email);
}
}

113 changes: 113 additions & 0 deletions SchoolManagerModel/ModelClassDiagram.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1" MembersFormat="FullSignature">
<Class Name="SchoolManagerModel.Persistence.ClassDatabase" BaseTypeListCollapsed="true">
<Position X="23.25" Y="14.25" Width="3.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAABAAACAAAABAAAACAAAQAAAAAAAAAAAAA=</HashCode>
<FileName>Persistence\ClassDatabase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="SchoolManagerModel.Persistence.SchoolDbContext">
<Position X="12" Y="6.25" Width="4.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAQAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Persistence\SchoolDbContext.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Persistence.SchoolDbContextBase">
<Position X="12" Y="2" Width="4.25" />
<TypeIdentifier>
<HashCode>AAIAAGAAAwEAAAAAAAAAAQAAEgAAAAAAAAQAAgAAAAA=</HashCode>
<FileName>Persistence\SchoolDbContextBase.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Persistence.SubjectDatabase" BaseTypeListCollapsed="true">
<Position X="7.5" Y="14.75" Width="5.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAABAAAAAABBAAAAAAAAAAAAAAQAEIAAAg=</HashCode>
<FileName>Persistence\SubjectDatabase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="SchoolManagerModel.Persistence.TeacherDatabase" BaseTypeListCollapsed="true">
<Position X="13.5" Y="14.25" Width="4.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAhAAAAAAAAQAAAAAECAAEAAAAAAAAAAA=</HashCode>
<FileName>Persistence\TeacherDatabase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="SchoolManagerModel.Persistence.UserDatabase" BaseTypeListCollapsed="true">
<Position X="18.75" Y="15.5" Width="4" />
<TypeIdentifier>
<HashCode>AAAgAAAFQAAAAgAAEAAAAICAAAIAAAAAAAAQAQAABQA=</HashCode>
<FileName>Persistence\UserDatabase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="SchoolManagerModel.Managers.ClassManager">
<Position X="23.25" Y="9.5" Width="3.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAABAAACAAAAAAAAACAAAQAAAAAAAAAAAAA=</HashCode>
<FileName>Managers\ClassManager.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Managers.LoginManager">
<Position X="18" Y="5.75" Width="3.5" />
<TypeIdentifier>
<HashCode>AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Managers\LoginManager.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Managers.SubjectManager">
<Position X="7.5" Y="9" Width="5.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAhAAAAAABAAAAAAAAAAAAABAQAEIAAAA=</HashCode>
<FileName>Managers\SubjectManager.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Managers.TeacherManager">
<Position X="13.5" Y="10" Width="4.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAEAAIAAAAAAAAAAAA=</HashCode>
<FileName>Managers\TeacherManager.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="SchoolManagerModel.Managers.UserManager">
<Position X="18.75" Y="8" Width="4" />
<TypeIdentifier>
<HashCode>AAAAAAAVQAAAAAAAEAgAAICAAAIAAAAAAAAQAAgABQA=</HashCode>
<FileName>Managers\UserManager.cs</FileName>
</TypeIdentifier>
</Class>
<Interface Name="SchoolManagerModel.Persistence.IAsyncClassDataHandler">
<Position X="23.5" Y="12" Width="3.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAABAAACAAAABAAAACAAAQAAAAAAAAAAAAA=</HashCode>
<FileName>Persistence\IAsyncClassDataHandler.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="SchoolManagerModel.Persistence.IAsyncSubjectDataHandler">
<Position X="8" Y="12" Width="4.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAABAAAAAABBAAAAAAAAAAAAAAQAEIAAAg=</HashCode>
<FileName>Persistence\IAsyncSubjectDataHandler.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="SchoolManagerModel.Persistence.IAsyncTeacherDataHandler">
<Position X="13.75" Y="12" Width="4.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAhAAAAAAAAQAAAAAEAAAEAAAAAAAAAAA=</HashCode>
<FileName>Persistence\IAsyncTeacherDataHandler.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="SchoolManagerModel.Persistence.IAsyncUserDataHandler">
<Position X="19" Y="11.75" Width="3.5" />
<TypeIdentifier>
<HashCode>AAAgAAAFQAAAAgAAEAAAAICAAAIAAAAAAAAQAQAABQA=</HashCode>
<FileName>Persistence\IAsyncUserDataHandler.cs</FileName>
</TypeIdentifier>
</Interface>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
8 changes: 5 additions & 3 deletions SchoolManagerModel/Persistence/IAsyncUserDataHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SchoolManagerModel.Entities;
using SchoolManagerModel.DTOs;
using SchoolManagerModel.Entities;
using SchoolManagerModel.Entities.UserModel;

namespace SchoolManagerModel.Persistence;
Expand All @@ -12,10 +13,11 @@ public interface IAsyncUserDataHandler
public Task<bool> EmailAlreadyRegisteredAsync(string email);
public Task AssignRoleAsync(User user, Role role);
public Task AddUserAsync(User user);
public Task<List<User>> GetUsersAsync();
public Task<List<UserDto>> GetUsersAsync();
public Task AddStudentAsync(Student student);
public Task AddTeacherAsync(Teacher teacher);
public Task AddAdminAsync(Admin admin);

public Task<Student?> GetStudentByUserAsync(User user);
public Task<List<UserDto>> FilterUsersAsync(string? username = null, string? firstName = null, string? lastName = null, string? email = null);

}
18 changes: 2 additions & 16 deletions SchoolManagerModel/Persistence/SchoolDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.EntityFrameworkCore;
using SchoolManagerModel.Entities;
using SchoolManagerModel.Entities.UserModel;
using SchoolManagerModel.Utils;

namespace SchoolManagerModel.Persistence;
Expand All @@ -14,19 +12,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Change password after first run!
var admin = new User("admin", HashStringMd5.GetHashedString("admin"), "[email protected]", "firstName",
"secondName")
{
Id = 1
};
modelBuilder.Entity<User>().HasData(admin);

// Assign administrator role to default account
var adminRole = new RoleRecord(1, 2)
{
Id = 1
};
modelBuilder.Entity<RoleRecord>().HasData(adminRole);
var seeder = new EntityDataSeeder(modelBuilder);
seeder.SeedAllData();
}
}
4 changes: 3 additions & 1 deletion SchoolManagerModel/Persistence/SubjectDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public async Task<List<Student>> GetSubjectStudentsAsync(Subject subject)
public async Task<List<Mark>> GetStudentMarksAsync(Student student)
{
return await dbContext.Marks
.Include(x => x.Subject).ThenInclude(x => x.Teacher)
.Include(x => x.Subject)
.ThenInclude(x => x.Teacher)
.ThenInclude(x => x.User)
.Where(x => x.Student == student)
.ToListAsync();
}
Expand Down
Loading

0 comments on commit b76cda5

Please sign in to comment.