I have a user class that has the attribute permissão
, which should always be 1. Where and how would I do to set this value? In the folder models
, controller
or in the view
of cadastre?
I have a user class that has the attribute permissão
, which should always be 1. Where and how would I do to set this value? In the folder models
, controller
or in the view
of cadastre?
No Model, more specifically in the constructor:
public class Usuario
{
...
public int Permissao { get; set; }
public Usuario() {
Permissao = 1;
}
}
To prevent modifying the value (read-only property), you can do the following:
public class Usuario
{
...
public int Permissao { get { return 1; } }
}
To prevent the value from being mapped in the Entity Framework (if you are using it), use [NotMapped]
:
public class Usuario
{
...
[NotMapped]
public int Permissao { get { return 1; } }
}
I would use:
public class Usuario
{
...
public const int Permissao = 1;
}
If it is always just a number without rules, no validations with nothing, then it makes perfect sense to be a constant and ready:)