samedi 6 août 2016

Handle array of multiple settings applicable for the entire application

I am developing a web application using asp.net MVC. This is the scenario.

I have a list of below Setting and Permission class:

class Settings
{
  public long SettingsId { get; set; }
  public string SettingsName { get; set; }
  public bool SettingsValue { get; set; }
}

class Permissions
    {
      public long Id { get; set; }
      public string Name { get; set; }          
    }

Based on the value in these class I will have to determine whether a particular task can be performed or not.

For e.g.

if (Settings.ContainsKey("Set1") && Settings["Set1"])
{
  if ((Permissions.ContainsKey("Perm1") && 
    Permissions["Perm1"]) || 
    (Settings.ContainsKey("Set2") && Settings["set2"]))
    {
      // Perform some operation or enable disbale a button etc.
    }
}

  • The settings could be dependent on another, as in above case Set1 and Set2.
  • Settings could be needed in cshtml page as well as Javascript.
  • Same setting can be applied at different pages.

I want to achieve the following :

  1. Avoid using these many if else wherever these settings are to be checked.
  2. A single place where all these settings are checked and requested on need basis.
  3. Some way of logical groping if possible, so that in future one can easily look for all the settings applied in the page.

Any ideas please?

Aucun commentaire:

Enregistrer un commentaire