I am to make re use the variables, without creating new variables and class everytime.
For example,
I have UserAuthentication Api controller
public class AuthController : ControllerBase
{
[HttpPost("register")]
public async Task<ActionResult<UserAuth>> Register(UserRegister registerRequest)
{
//....
}
[HttpPost("Login")]
public async Task<ActionResult<string>> Login(UserLogin loginRequest)
{
//....
}
}
I created Model class like be below
namespace DemoAsp.Models.User
{
public class UserLogin
{
public string Username { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
public class UserRegister : UserLogin
{
// I will use the Variable Username and Password from base class "UserLogin"
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string ConfirmPassword { get; set; } = string.Empty;
}
public class UserData : UserRegister
{
// I will use the all the Variables from both class "UserLogin" and "UserRegister", In case I need it.
}
}
I don't think this is the way to organize the MODEL Class and their fields. If I define the variable separately for UserRegister and UserLogin, then the variable name will be repeat
Could someone suggest me the way to handle/organize the Model class.
So that it will be helpful to create and maintain any other models