Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Static method in the public class
Message
 
 
À
09/08/2016 07:18:21
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01639234
Message ID:
01639238
Vues:
48
>>Hi everybody,
>>
>>We have the following class:
>>
>>
>> [Serializable]
>>    public class OperatorSession
>>    {
>>        public OperatorSession()
>>        {
>>            Rights = new string[0];
>>            Roles = new List<SecRole>();
>>        }
>>
>>        public string OpCode { get; set; }'
>>        etc.
>>
>>
>>      public static bool IsAdmin(string opCode)
>>        {
>>            return !String.IsNullOrEmpty(opCode) && opCode.Trim().ToLower() == SysManagerConstants.ADMIN_OPCODE.ToLower();
>>        }
>>
>>
>>The problem here is that IsAdmin definition changed. Now in addition of the opCode being some specific code this method should also return true when the operator has the following role X_SYSADMIN.
>>
>>I am not able to add a check for Rights.contains in the static method and so I'm at loss as how can I check what I need to check.
>>
>>My other problem is that OperatorSession class is defined in the Models project. This project only contains classes definitions and it doesn't reference anything else. There is another project called Data which has Models as a reference. So, from the OperatorSession I can not even access DbSet to try to get an instance of the operator by the code to check operator's roles.
>>
>>I also checked that we do use something like this in the code:
>>
>>return OperatorSession.IsAdmin(id) || rights.Contains("SEC_OEDIT");
>>
>>
>>
>>I guess I need to create a different non static method to check if operator is an admin.
>>
>>Thanks in advance.
>
>Have not understood completely, but
>
>(1) You can add the same method with a different signature if necessary
>
>(2) Rights class can be a static property of OperatorSession class - if needed
>
>(3) You can always instantiate an object in a static method

I've added a new static method
 public static bool IsAdmin(string opCode, string[] rights)
        {
            return IsAdmin(opCode) || rights.Contains("X_SYSADMIN");
        }
and changed all calls to original static method to this one. Now I'm testing the functionality.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform