I have three classes , user, admin and teacher,where admin and teacher inherit from user class. All of the have the same properties, except that in admin I set a property named role to enum.admin and in teacher I set that property to enum.teacher. I have two questions here.
First when I try to cast an object of type user to admin, I receive "unable to cast object of type User to type Admin" error. I don't know why I receive this error, while all the properties in user class and admin are all the same also it's the same for teacher.
My second question is that,in my web application, I want to authenticate the user and return and object of the user class when the authentication is successful. In the web page(code behind) , I check the role property of that user object,if it is teacher i want to cast it to teacher class and if it is admin cast it to admin.(which fails as in my first question). I was wondering whether i am making a good design and solution for this purpose (having multiple types of users) by having a general user class and two inherited teacher and admin class. Or maybe there could be better and more object-oriented solutions than this ? Any suggestions?