/// <summary> /// Create New Role /// </summary> /// <param name="Name"></param> /// <param name="userLevel"></param> /// <param name="OrgID"></param> /// <returns></returns> public String AddNewRole(string Name, string userLevel, List <int> OrgID) { string info = ""; string msg; int AD_Role_Table_ID = Convert.ToInt32(DB.ExecuteScalar("SELECT AD_Table_ID FROM AD_Table WHERE TableName='AD_Role'", null, null)); try { string sql = @"SELECT AD_Column_ID,ColumnName, defaultvalue FROM AD_Column WHERE AD_Table_ID =" + AD_Role_Table_ID + @" AND isActive ='Y' AND defaultvalue IS NOT NULL"; DataSet ds = DB.ExecuteDataset(sql); // Get Default Values if (ds == null || ds.Tables[0].Rows.Count == 0) { return(VAdvantage.Utility.Msg.GetMsg(ctx, "DefaultValueNotFound")); } MRole role = new MRole(ctx, 0, null); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // Setting Default Values { string value = ds.Tables[0].Rows[i]["DefaultValue"].ToString(); if (value.StartsWith("@")) { value = value.Substring(0, value.Length - 1); string columnName = value.Substring(value.IndexOf("@") + 1); value = ctx.GetContext(columnName); // get global context } role.Set_Value(ds.Tables[0].Rows[i]["ColumnName"].ToString(), value); } role.SetIsManual(true); role.SetName(Name); role.SetUserLevel(userLevel); if (role.Save()) { if (OrgID != null) { for (int i = 0; i < OrgID.Count; i++) // Assigning org access to role { MOrg org = new MOrg(ctx, OrgID[i], null); MRoleOrgAccess roles = new MRoleOrgAccess(org, role.GetAD_Role_ID()); roles.SetAD_Client_ID(ctx.GetAD_Client_ID()); roles.SetAD_Org_ID(OrgID[i]); roles.SetIsReadOnly(false); roles.Save(); } } } else { ValueNamePair ppE = VAdvantage.Logging.VLogger.RetrieveError(); if (ppE != null) { msg = ppE.GetValue(); info = ppE.GetName(); } } return(info); } catch (Exception ex) { return(ex.Message); } //rr.Set_Value( }
/// <summary> /// Create New Role /// </summary> /// <param name="Name"></param> /// <param name="userLevel"></param> /// <param name="OrgID"></param> /// <returns></returns> public bool AddNewRole(string Name, string userLevel, List <int> OrgID) { var retValue = false; int AD_Role_Table_ID = Convert.ToInt32(DB.ExecuteScalar("SELECT AD_Table_ID FROM AD_Table WHERE TableName='AD_Role'", null, null)); try { string sql = @"SELECT AD_Column_ID,ColumnName, defaultvalue FROM AD_Column WHERE AD_Table_ID =" + AD_Role_Table_ID + @" AND isActive ='Y' AND defaultvalue IS NOT NULL"; DataSet ds = DB.ExecuteDataset(sql); // Get Default Values if (ds == null || ds.Tables[0].Rows.Count == 0) { return(false); } MRole role = new MRole(ctx, 0, null); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // Setting Default Values { string value = ds.Tables[0].Rows[i]["DefaultValue"].ToString(); if (value.StartsWith("@")) { value = value.Substring(0, value.Length - 1); string columnName = value.Substring(value.IndexOf("@") + 1); value = ctx.GetContext(columnName); // get global context } role.Set_Value(ds.Tables[0].Rows[i]["ColumnName"].ToString(), value); } role.SetIsManual(true); role.SetName(Name); role.SetUserLevel(userLevel); if (role.Save()) { if (OrgID != null) { for (int i = 0; i < OrgID.Count; i++) // Assigning org access to role { MOrg org = new MOrg(ctx, OrgID[i], null); MRoleOrgAccess roles = new MRoleOrgAccess(org, role.GetAD_Role_ID()); roles.SetAD_Client_ID(ctx.GetAD_Client_ID()); roles.SetAD_Org_ID(OrgID[i]); roles.SetIsReadOnly(false); roles.Save(); } retValue = true; } else { retValue = true; } } } catch { retValue = false; } //rr.Set_Value( return(retValue); }