private static void InitAuthorizationNameMap()
 {
     if (FeaturePropertiesMap == null || FeaturePropertiesMap.Count == 0)
     {
         InitFeatureProperties();
     }
     if (AuthorizationMap == null || AuthorizationMap.Count == 0)
     {
         AuthorizationMap = DefinitionDao.GetUserAuthorizationMap();
     }
     foreach (var pair in AuthorizationMap)
     {
         List <int>    ListFeatureId   = pair.Value;
         List <string> ListFeatureName = new List <string>();
         foreach (int id in ListFeatureId)
         {
             FeatureAttribute attr = ListFeatureAttribute.FirstOrDefault(n => n.Id == id);
             if (attr == null)
             {
                 continue;
             }
             ListFeatureName.Add((attr.Name + attr.Group).ToKey());
         }
         AuthorizationNameMap[pair.Key] = ListFeatureName;
     }
 }
        public static bool isAuthorized(Type featureType)
        {
            if (Config.Manager.CURRENT_USER == null)
            {
                return(false);
            }
            string userType = Config.Manager.CURRENT_USER.UserType;
            var    feature  = featureType.GetCustomAttributes(typeof(FeatureAttribute), true).FirstOrDefault() as FeatureAttribute;

            if (feature == null)
            {
                return(false);
            }
            if (FeaturePropertiesMap == null || FeaturePropertiesMap.Count == 0)
            {
                InitFeatureProperties();
            }
            if (AuthorizationMap == null || AuthorizationMap.Count == 0)
            {
                AuthorizationMap = DefinitionDao.GetUserAuthorizationMap();
            }
            //Check
            if (!AuthorizationMap.ContainsKey(userType))
            {
                return(false);
            }
            return(AuthorizationMap.GetValue(userType).Contains(feature.Id));
        }
 public static List<DefinitionDto> GetAllCategory()
 {
    if (ListCategories == null || ListCategories.Count == 0)
    {
       ListCategories = DefinitionDao.GetCategoryList();
    }
    return ListCategories;
 }
 public static Dictionary <string, List <int> > GetAuthorizationMap()
 {
     if (AuthorizationMap == null || AuthorizationMap.Count == 0)
     {
         AuthorizationMap = DefinitionDao.GetUserAuthorizationMap();
     }
     return(AuthorizationMap);
 }
 public static int InsertCategory(string categoryName)
 {
    DefinitionDto dto = new DefinitionDto();
    dto.DefinitionType = CONST.DEFINITION.DEFINITION_TYPE_CATEGORY;
    dto.Value1 = categoryName;
    int id = DefinitionDao.Insert(dto);
    dto.DefinitionId = id;
    ListCategories.Add(dto);
    return id;
 }
      public static bool UpdateAuthorization(DefinitionDto dto, String name, List<String> FeaturesName)
      {
         var featureMap = FeatureAttributeService.GetFeaturePropertiesNameMap();
         List<int> values = FeaturesName.Select(n => featureMap.GetValue(n)).Where(n => n != 0).ToList();
         var authorizationMap = FeatureAttributeService.GetAuthorizationMap();
         FeatureAttributeService.UpdateAuthorizationNameMap(name, values);
         authorizationMap.Remove(dto.Value1);
         authorizationMap[name] = values;

         dto.Value1 = name;
         dto.Value2 = String.Join(",", values);
         return DefinitionDao.Update(dto);
      }
 public static bool UpdateCategory(DefinitionDto dto)
 {
    DefinitionDto oldDto = ListCategories.FirstOrDefault(n => n.DefinitionId == dto.DefinitionId);
    bool result = DefinitionDao.Update(dto);
    if (result)
    {
       if (oldDto != null)
          ListCategories.Remove(oldDto);
       ListCategories.Add(dto);
       ListCategories.OrderBy(n => n.DefinitionId);
    }
    return result;
 }
      public static DefinitionDto InsertAuthorization(String name, List<String> FeaturesName)
      {
         var featureMap = FeatureAttributeService.GetFeaturePropertiesNameMap();
         List<int> values = FeaturesName.Select(n => featureMap.GetValue(n)).Where(n => n != 0).ToList();

         DefinitionDto dto = new DefinitionDto();
         dto.DefinitionType = CONST.DEFINITION.DEFINITION_TYPE_AUTHORIZATION;
         dto.Value1 = name;
         dto.Value2 = String.Join(",", values);
         int id = DefinitionDao.Insert(dto);
         dto.DefinitionId = id;

         var authorizationMap = FeatureAttributeService.GetAuthorizationMap();
         authorizationMap[name] = values;
         FeatureAttributeService.UpdateAuthorizationNameMap(name, values);
         return dto;
      }
 public static bool isAuthorized(string userType, int featureId)
 {
     if (FeaturePropertiesMap == null || FeaturePropertiesMap.Count == 0)
     {
         InitFeatureProperties();
     }
     if (AuthorizationMap == null || AuthorizationMap.Count == 0)
     {
         AuthorizationMap = DefinitionDao.GetUserAuthorizationMap();
     }
     //Check
     if (!AuthorizationMap.ContainsKey(userType))
     {
         return(false);
     }
     return(AuthorizationMap.GetValue(userType).Contains(featureId));
 }
 public static bool DeleteAuthorization(DefinitionDto dto)
 {
    if (dto.Value1.Equals("ADMIN"))
       return false;
    return DefinitionDao.Delete(dto);
 }