I'd like to know if the following scenario is possible with the Multitenant feature in AspNetZero:
A school can subscribe to a plan. (school = Tenant)
A school has multiple teachers A school has multiple students
Each teacher could have one or more students Each student could have one ore more teachers.
I assume that the already available Users within a Tenant could be either a teacher or a student. Maybe based on Roles??
Any suggestions on how I should model this? I don't want to create new Entities if I probably can re-use the builtin Users?
Is that a correct assumption?
Thanks, Daniel
12 Answer(s)
-
0
Hi @zimplerconsulting
Yes, you can definitely use Roles to separete Teachers and Students.
Each teacher could have one or more students Each student could have one ore more teachers.
You have to create a relation entity (table) between Users to achieve this.
-
0
Hi @ismcagdas,
Thanks for the follow up. Could you eleborate a bit more on this relation entity? If I can make a User a 'Teacher or Student or Both' based on Roles, why would I need a relation? And between which entities you mean?
Hope you can help me some more.
Thanks, Daniel
-
0
@zimplerconsulting
Sorry I got it wrong. I thougt Students can have Teachers and vice versa but tou were talking about Schools having Users and Teachers.
-
0
Yes. That is correct.
So I guess a School can be just the Tenant.
Every User inside the Tenant can be either a Teacher, a Student or both. But indeed, now I think about it: a Student could have one or more Teachers and a Teacher could have one or more Students.
So yeah, do I need multiple entities for this or can I re-use the Users for this and extend that entity?
Best, Daniel
-
0
If you want to have a relation between Student and Teacher, then as I said before, you can create a relation entity. It is better to keep track for such relation.
-
0
OK, but do I need to create separate Entities for Students and Teachers? I mean, can I re-use the Users from a Tenant for this? Because a User can login to a Tenant app.
If I need the same functionality for a Student or Teacher, it seems a bit overkill to create exactly the same Entities.
But maybe I don't get the concept of a relation entity. What is it?
-
0
OK, but do I need to create separate Entities for Students and Teachers? I mean, can I re-use the Users from a Tenant for this? Because a User can login to a Tenant app.
Yes, you can use User entity for that, sure.
-
0
Thanks! Ehm... any example on this? How would you do this in AspnetZero?
Sorry, it's just not quite clear :(
-
0
Hi @zimplerconsulting
Your application has students and teachers who are users basically. So a user can be a student or teacher or whatever(maybe admin or something). You can create a roles 'Teacher' and 'Student', and grant those roles to your users. Then when a user logged in you can check if the student/teacher role granted to the user and then you can run your logic.
You can check these: https://aspnetboilerplate.com/Pages/Documents/Authorization, https://aspnetboilerplate.com/Pages/Documents/Zero/Permission-Management
For the second part of your requirement, a student can have teachers, and teachers can have student. It means you need many to many relations. Basically you can create an entity something like,
[Table("TeachersAndStudents")] public class TeachersAndStudents : Entity, IMayHaveTenant { public long StudentId { get; set; } public long TeacherId { get; set; } public int? TenantId { get; set; } [ForeignKey("StudentId")] public virtual User Student { get; set; } [ForeignKey("TeacherId")] public virtual User Teacher { get; set; } ... }
then you can use
//add teacher 2 to student 1, in other words, add student1 to teacher2 (IRepository<TeachersAndStudents>).Insert(new TeachersOfStudent { StudentId = 1, TeacherId = 2, TenantId = AbpSession.TenantId })
then you can query them with something like
var teachersOfStudent = (IRepository<TeachersAndStudents>).GetAll().Where(x=>x.StudentId == 1).Tolist(); var studentsOfTeacher = (IRepository<TeachersAndStudents>).GetAll().Where(x=>x.TeacherId == 2).Tolist();
-
0
Ah ok. I see. That makes sense. Thanks!
And it would be possible to extend the User screens with e.g. possibilites to select teachers or students? (e.g. with a dropdown or so). I don't know if there are any examples for such a case like this? Or any other many-to-many examples?
-
0
Yes, that is possible but there is no example in the default template. You need to implement it yourself.
-
0
@zimplerconsulting please reopen this issue if you face any problems.