private bool Map_Responder_Contact() { string msg; bool isMatch = false; try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@contact_def", _contact_def)); // DataRow drAgency = _stageProvider.GetData("SYNC_Map_Responder_Contact", _sqlParms).Rows[0]; DataTable dtMapContact = _stageProvider.GetData("SYNC_Map_Responder_Contact", _sqlParms); if (dtMapContact.Rows.Count > 0) { DataRow dr = dtMapContact.Rows[0]; _SubscriberResponder_ID = dr["SubscriberResponder_ID"].Parse <int>(); _Subscriber_ID = dr["Subscriber_ID"].ToString(); isMatch = true; EntityMessage(string.Format("SubscriberResponder Id {0} found for contact_def {1}", _SubscriberResponder_ID.ToString(), _contact_def.ToString()), "INFO"); } else { EntityMessage(string.Format("No mapping found for contact_def {0}. Row Count: {1}", _contact_def.ToString(), dtMapContact.Rows.Count.ToString()), "INFO"); } } catch (Exception ex) { EntityMessage(string.Format("Map_Responder_Contact had a fatal error mapping contact_def {0}. ERROR: {1}", _contact_def.ToString(), ex.Message), "ERROR"); } return(isMatch); }
public override void ProcessDataDelete() { bool isMapped = true; // map the fields try { _contact_def = this._dataToMapp["contact_def"].Parse <int>(); //_contact_type_ref = this._dataToMapp["contact_type_ref"].Parse<int>(); _residentDef = this._dataToMapp["resident_ref"].Parse <int>(); } catch (Exception ex) { this.EntityMessage(string.Format("Failed to map contact_def {0} in Contact.ProcessDataDelete. ERROR: {1}", _contact_def.ToString(), ex.Message), "ERROR"); isMapped = false; } if (isMapped) { try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@contact_def", _contact_def)); _sqlParms.Add(SQLParam.GetParam("@resident_def", _residentDef)); _stageProvider.ExecuteNonQuery("SYNC_Process_Responder_Delete", _sqlParms); this.EntityMessage(string.Format("Processed responder delete for contact_def {0}", _contact_def), "INFO"); } catch (Exception ex) { this.EntityMessage(string.Format("Unable to process responder delete for contact_def: {0}. ERROR: {1}", _contact_def.ToString(), ex.Message), "ERROR"); } } }
public void Move_Change_Log_Transactions(string group_record) { List <SQLParam> parms = new List <SQLParam>(); parms.Add(SQLParam.GetParam("@group_record", group_record)); _stageProvider.ExecuteNonQuery("SYNC_Move_EtlChangeLog_Stage", parms); }
private string PNC_EPEC_MAP() { string processType = "INSERT"; try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@locdef", _locationDef)); _sqlParms.Add(SQLParam.GetParam("@resdef", _residentDef)); _sqlParms.Add(SQLParam.GetParam("@subscriber", "-1")); //_Subscriber_ID = _stageProvider.ExecuteScalar<string>("SYNC_Map_Subscriber_Location", _sqlParms); DataRow dr = _stageProvider.ExecuteDataSet("SYNC_Map_Subscriber_Location", _sqlParms).Tables[0].Rows[0]; _Subscriber_ID = dr["Subscriber_ID"].ToString(); _MasterReference = dr["MasterReference"].ToString(); if (_Subscriber_ID != "-1") { processType = "UPDATE"; EntityMessage(string.Format("Subscriber Id {0} found for location_def {1}", _Subscriber_ID, _locationDef.ToString()), "INFO"); } else { processType = "INSERT"; EntityMessage(string.Format("No Subscriber Id found for location_def {0}", _locationDef.ToString()), "INFO"); } } catch (Exception ex) { processType = "NONE"; EntityMessage(string.Format("Failed to map subsciber to location for location_def {0}. Error: {1}", _locationDef.ToString(), ex.Message), "ERROR"); } return(processType); }
bool Map_Subscriber() { bool isMapped = true; try { _sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@locdef", this._locationDef)); this._sqlParms.Add(SQLParam.GetParam("@resdef", this._residentDef)); this._sqlParms.Add(SQLParam.GetParam("@subscriber", "-1")); _Subscriber_ID = _stageProvider.ExecuteScalar <string>("SYNC_Map_Subscriber_Resident", _sqlParms); if (_Subscriber_ID != "-1") { this.EntityMessage(string.Format("Subscriber Id {0} found for call_def {1}", this._Subscriber_ID, this._call_def), "INFO"); } else { this.EntityMessage(string.Format("No Subscriber Id found for call_def {0}", this._call_def), "INFO"); isMapped = false; } } catch (Exception ex) { isMapped = false; this.EntityMessage(string.Format("Failed to map subscriber for call_def {0}. Error: {1}", _dataToMapp["call_def"].ToString(), ex.Message), "ERROR"); } return(isMapped); }
static public bool WriteUpdatetekst(TrnRec ATrnRec) { try { SQL.SQLParams.Clear(); SQLParam P = new SQLParam { PName = "NLVal", PType = SqlDbType.VarChar, PValue = ATrnRec.NL }; SQL.SQLParams.Add(P.PName, P); P = new SQLParam { PName = "ENVal", PType = SqlDbType.VarChar, PValue = ATrnRec.EN }; SQL.SQLParams.Add(P.PName, P); P = new SQLParam { PName = "DEVal", PType = SqlDbType.VarChar, PValue = ATrnRec.DE }; SQL.SQLParams.Add(P.PName, P); SQL.InsertUpdateQuery("UPDATE tbl_Translate SET EN = @ENValue, DE = @DEValue WHERE NL = @NLValue"); return(true); } catch { return(false); } }
public void ProcessDataFlow() { bool processrelation = this.Map_Contact_Relation_Fields(); if (processrelation) { try { _sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@process_type", "PNC")); this._sqlParms.Add(SQLParam.GetParam("@subscriber", "-1")); this._sqlParms.Add(SQLParam.GetParam("@subscriber_responder", "-1")); this._sqlParms.Add(SQLParam.GetParam("@location_ref", this._locationDef.ToString())); this._sqlParms.Add(SQLParam.GetParam("@resident_ref", this._residentDef.ToString())); this._sqlParms.Add(SQLParam.GetParam("@contact_ref", this._contact_def.ToString())); this._sqlParms.Add(SQLParam.GetParam("@type_ref", this._contact_type_ref.ToString())); this._sqlParms.Add(SQLParam.GetParam("@priority", this._priority)); _stageProvider.ExecuteNonQuery("SYNC_Process_ContactRelation", _sqlParms); this.EntityMessage(string.Format("Processed contact relation for contact_def {0}, relation_def {1}", _contact_def.ToString(), _relation_def), "INFO"); } catch (Exception ex) { this.EntityMessage(string.Format("Unable to process contact relation for contact_def {0}, relation_def {1}", _contact_def, _relation_def), "ERROR"); } } }
private bool Keyword_Map_Subscriber_Resident() { bool isMapped = true; try { _sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@locdef", _locationDef)); this._sqlParms.Add(SQLParam.GetParam("@resdef", _residentDef)); this._sqlParms.Add(SQLParam.GetParam("@subscriber", "-1")); _Subscriber_ID = _stageProvider.ExecuteScalar <string>("SYNC_Map_Subscriber_Resident", _sqlParms); if (_Subscriber_ID == "-1") { isMapped = false; } } catch (Exception ex) { this.EntityMessage(string.Format("Keyword_Map_Subscriber_Resident error: {0} on resident_def {1}.", ex.Message, _residentDef.ToString()), "ERROR"); isMapped = false; } //this.EntityMessage(string.Format("Keyword_Map_Subscriber_Resident is_mapped: {0} on resident_def {1}.", isMapped.ToString(), _residentDef.ToString())); return(isMapped); }
private bool Subscriber_Medical_Info_Lookup() { bool isMapped = true; try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@subscriber_ID", _Subscriber_ID)); _sqlParms.Add(SQLParam.GetParam("@id", _Code)); _sqlParms.Add(SQLParam.GetParam("@type", _type)); _SubscriberMedicalInfo = _stageProvider.ExecuteScalar <int>("SYNC_Subscriber_Medical_Info_Lookup", _sqlParms); if (_SubscriberMedicalInfo == -1) { isMapped = false; } } catch (Exception ex) { this.EntityMessage(string.Format("Map_SubMedInfo_To_Keyword error: {0} on resident_def {1}, keyword_ref {2}.", ex.Message, _residentDef.ToString(), _keyword_ref.ToString()), "INFO"); isMapped = false; } //this.EntityMessage(string.Format("Subscriber_Medical_Info_Lookup is_mapped {0} for Subscriber_ID {1} Type {2} Code {3}.",isMapped.ToString(),_Subscriber_ID,_type,_Code)); return(isMapped); }
static public bool WriteNewTekst(TrnRec ATrnRec) { try { SQL.SQLParams.Clear(); SQLParam P = new SQLParam { PName = "NLVal", PType = SqlDbType.VarChar, PValue = ATrnRec.NL }; SQL.SQLParams.Add(P.PName, P); P = new SQLParam { PName = "ENVal", PType = SqlDbType.VarChar, PValue = ATrnRec.EN }; SQL.SQLParams.Add(P.PName, P); P = new SQLParam { PName = "DEVal", PType = SqlDbType.VarChar, PValue = ATrnRec.DE }; SQL.SQLParams.Add(P.PName, P); SQL.InsertUpdateQuery("INSERT INTO tbl_Translate (NL, EN, DE) VALUES (@NLValue, @ENValue, @DEValue)"); return(true); } catch { return(false); } }
public void GrantPermission(string mObject, string mOperation, string[] mRoles) { if (_App == null) { return; } string HQL = "from role r where r.AppID = :AppID AND r.name in ({0})"; string ParaStr = ":" + string.Join(",:", mRoles); HQL = string.Format(HQL, ParaStr); SQLParam[] paramList = new SQLParam[mRoles.Length + 1]; paramList[0] = new SQLParam("AppID", _App.AppID); for (int i = 0; i < mRoles.Length; i++) { paramList[i + 1] = new SQLParam(mRoles[i], mRoles[i]); } List <role> RoleLst = RoleSrv.GetbyHQuery(HQL, paramList); if (RoleLst == null || RoleLst.Count == 0) { return; } //Grant permission permission TempPermission = PermissionSrv.GetPermission(mObject, mOperation, _App.AppID); if (TempPermission == null) { objectRbac tempObject = ObjectSrv.GetByName(mObject, _App.AppID); operation tempOperation = OperationSrv.GetByName(mOperation, _App.AppID); if (tempObject == null || tempOperation == null) { return; } TempPermission = new permission(); TempPermission.AppID = _App.AppID; TempPermission.name = tempObject.name + ":" + tempOperation.name; TempPermission.ObjectRBAC = tempObject; TempPermission.Operation = tempOperation; TempPermission.Roles = new List <role>(); foreach (role r in RoleLst) { TempPermission.Roles.Add(r); } PermissionSrv.CreateNew(TempPermission); PermissionSrv.CommitChanges(); } else { foreach (role r in RoleLst) { if (!TempPermission.Roles.Contains(r)) { TempPermission.Roles.Add(r); } } PermissionSrv.CommitChanges(); } }
/// <summary> /// remove all oldrole assign for the permission and assign new [mRoles] for the permission /// </summary> /// <param name="mObject"></param> /// <param name="mOperation"></param> /// <param name="mRoles"></param> public void UpdatePermission(string mObject, string mOperation, string[] mRoles) { if (_App == null) { return; } IroleService RoleSrv = new roleService(SessionFactoryConfigPath); string HQL = "from role r where r.AppID = :AppID AND r.name in ({0})"; string ParaStr = ":" + string.Join(",:", mRoles); HQL = string.Format(HQL, ParaStr); SQLParam[] paramList = new SQLParam[mRoles.Length + 1]; paramList[0] = new SQLParam("AppID", _App.AppID); for (int i = 0; i < mRoles.Length; i++) { paramList[i + 1] = new SQLParam(mRoles[i], mRoles[i]); } //List<role> RoleLst = RoleSrv.GetbyHQuery(HQL, new SQLParam("rolenames", string.Join(",",mRoles)), new SQLParam("AppID", _App.AppID)); List <role> RoleLst = RoleSrv.GetbyHQuery(HQL, paramList); if (RoleLst == null || RoleLst.Count == 0) { return; } //Grant permission IpermissionService PermissionSrv = new permissionService(SessionFactoryConfigPath); permission TempPermission = PermissionSrv.GetPermission(mObject, mOperation, _App.AppID); if (TempPermission != null) { List <role> TmpRolseLst = new List <role>(); foreach (role r in TempPermission.Roles) { if (!RoleLst.Contains(r)) { TmpRolseLst.Add(r); } } foreach (role r in TmpRolseLst) { TempPermission.Roles.Remove(r); } foreach (role r in RoleLst) { if (!TempPermission.Roles.Contains(r)) { TempPermission.Roles.Add(r); } } PermissionSrv.CommitChanges(); } }
public void Update_Sync_Step(string step_name) { try { List <SQLParam> parms = new List <SQLParam>(); parms.Add(SQLParam.GetParam("@step_name", step_name)); _stageProvider.ExecuteNonQuery("SYNC_Update_Sync_Step", parms); } catch { } }
protected void LogServiceMessage(string serviceName, string log_type, string message) { try { List <SQLParam> parms = new List <SQLParam>(); parms.Add(SQLParam.GetParam("@service_name", serviceName)); parms.Add(SQLParam.GetParam("@log_type", log_type)); parms.Add(SQLParam.GetParam("@message", message)); _stageProvider.ExecuteNonQuery("SYNC_Insert_Sync_Log", parms); } catch { } }
public void Log_Service_Message(string log_type, string message) { try { List <SQLParam> parms = new List <SQLParam>(); parms.Add(SQLParam.GetParam("@service_name", "Kshema_PNC_Sync")); parms.Add(SQLParam.GetParam("@log_type", log_type)); parms.Add(SQLParam.GetParam("@message", message)); _stageProvider.ExecuteNonQuery("SYNC_Insert_Sync_Log", parms); } catch { } }
private void Save_Subscriber_Language(string command) { try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@subscriberId", _Subscriber_ID)); _sqlParms.Add(SQLParam.GetParam("@type", _type)); _sqlParms.Add(SQLParam.GetParam("@code", _Code)); _sqlParms.Add(SQLParam.GetParam("@command", command)); _stageProvider.ExecuteNonQuery("SYNC_Save_SubscriberLanguage", _sqlParms); } catch { } }
public void Save_Transaction_Record(string group_record, string entity, string transaction, string err_message) { try { List <SQLParam> parms = new List <SQLParam>(); parms.Add(SQLParam.GetParam("@group_record", group_record)); parms.Add(SQLParam.GetParam("@entity", entity)); parms.Add(SQLParam.GetParam("@transaction", transaction)); parms.Add(SQLParam.GetParam("@err_message", err_message)); _stageProvider.ExecuteNonQuery("SYNC_Insert_Transaction_Log", parms); } catch { } }
protected void LogServiceMessage(string log_type, string message) { try { Console.WriteLine(string.Format("{0} {1}", DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss"), message)); List <SQLParam> parms = new List <SQLParam>(); parms.Add(SQLParam.GetParam("@service_name", "Agency_Import")); parms.Add(SQLParam.GetParam("@log_type", log_type)); parms.Add(SQLParam.GetParam("@message", message)); _stageProvider.ExecuteNonQuery("SYNC_Insert_Sync_Log", parms); } catch { } }
private void Delete_Resident_Directions() { try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@entity_ref", _script_entity_ref)); _stageProvider.ExecuteNonQuery("SYNC_Delete_Resident_Directions", _sqlParms); this.EntityMessage(string.Format("Deleted resident direction for resident_def {0}", _script_entity_ref), "INFO"); } catch (Exception ex) { this.EntityMessage(string.Format("Unable to delete resident direction for resident_def: {0}. ERROR: {1}", _script_entity_ref.ToString(), ex.Message), "ERROR"); } }
private void _Process_Delete_Resonder_Contact_Note() { try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@entity_ref", _entity_ref)); _stageProvider.ExecuteNonQuery("SYNC_Delete_ResponderContact_Note", _sqlParms); this.EntityMessage(string.Format("Processed responder/contact note for note_def {0}", _entity_ref.ToString()), "INFO"); } catch (Exception ex) { this.EntityMessage(string.Format("Unable to delete responder/contact notes for note_def: {0}, entity_type: {1}. ERROR: {2}", _entity_ref.ToString(), _entity_type.ToString(), ex.Message), "ERROR"); } }
private void Process_Resident_Epec_Directions() { try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@note_entity", _note_entity)); _sqlParms.Add(SQLParam.GetParam("@note_text", _note_text)); _stageProvider.ExecuteNonQuery("SYNC_Process_Resident_NearestIntersection", _sqlParms); this.EntityMessage(string.Format("Processed resident_epec direction for note_entity {0}", _note_entity.ToString()), "INFO"); } catch (Exception ex) { this.EntityMessage(string.Format("Unable to process resident_epec direction for note_entity: {0}", _note_entity.ToString()), "ERROR"); } }
bool Can_Sync_Call_History() { bool can_sync = false; try { _sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@subscriber_id", this._Subscriber_ID)); can_sync = _stageProvider.ExecuteScalar <bool>("SYNC_Can_Sync_Call_History", _sqlParms); } catch { } return(can_sync); }
bool Subscriber_Has_Keyword() { bool has_keyword = false; try { this._sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@resident_def", this._resident_ref)); this._sqlParms.Add(SQLParam.GetParam("@keyword_def", this._keyword_def)); this._sqlParms.Add(SQLParam.GetParam("@keyword_no", this._keyword_num)); has_keyword = this._stageProvider.ExecuteScalar <bool>("SYNC_Subscriber_Has_Keyword", this._sqlParms); } catch {} return(has_keyword); }
private void Insert_Keyword_To_Queue() { try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@subscriber_ID", _Subscriber_ID)); _sqlParms.Add(SQLParam.GetParam("@Id", _Code)); _sqlParms.Add(SQLParam.GetParam("@type", _type)); _stageProvider.ExecuteNonQuery("SYNC_Insert_Keyword_SSIS_Q", _sqlParms); this.EntityMessage(string.Format("Insert_Keyword_To_Queue successfully inserted Type {0} Code {1} for Subscriber_Id {2}", _type, _Code, _Subscriber_ID), "INFO"); } catch (Exception ex) { this.EntityMessage(string.Format("Insert_Keyword_To_Queue failed to insert Type {0} Code {1} for Subscriber_ID {2}. ERROR: {3}", _type, _Code, _Subscriber_ID, ex.Message), "ERROR"); } }
protected bool Check_Agency_Mapping(string agency_id) { bool ismapped = false; try { this._sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@agency_id", agency_id)); ismapped = _stageProvider.ExecuteDataSet("SYNC_Is_Mapped_Agency ", this._sqlParms).Tables[0].Rows[0]["Is_Mapped"].Parse <bool>(); } catch (Exception ex) { EntityMessage(string.Format("Fatal exception in Check_Agency_Mapping for agency {0}. Error: {1}", agency_id, ex.Message), "ERROR"); } return(ismapped); }
private void Process_Responder_Contact_Note() { try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@notes_def", _notes_def)); _sqlParms.Add(SQLParam.GetParam("@note_entity", _note_entity)); _sqlParms.Add(SQLParam.GetParam("@entity_type", _entity_type)); _sqlParms.Add(SQLParam.GetParam("@note_title", _note_title)); _sqlParms.Add(SQLParam.GetParam("@note_text", _note_text)); _stageProvider.ExecuteNonQuery("SYNC_Process_Responder_Note", _sqlParms); this.EntityMessage(string.Format("Processed responder note for note_def {0}", _notes_def.ToString()), "INFO"); } catch (Exception ex) { this.EntityMessage(string.Format("Unable to process responder notes for note_def: {0}, entity_type: {1}, note_entity: {2}", _notes_def.ToString(), _entity_type.ToString(), _note_entity.ToString()), "ERROR"); } }
public void Fetch(string subscriber) { try { this._sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@subscriber", subscriber)); DataRow drMapping = _stageProvider.ExecuteDataSet("SYNC_Get_Subscriber_Mapping", this._sqlParms).Tables[0].Rows[0]; _location_def = drMapping["Location_Ref"].Parse <int>(); _resident_def = drMapping["Resident_Def"].Parse <int>(); _authority_ref = drMapping["Authority_Ref"].Parse <int>(); _equip_id = drMapping["Equip_Id"].Parse <long>(); _subscriber = subscriber; } catch (Exception ex) { this.EntityMessage(string.Format("Failed to fetch the subscriber mapping for {0}", subscriber), "ERROR"); } }
private bool Map_Resident_Characteristic() { bool isMatch = false; try { _sqlParms = new List <SQLParam>(); _sqlParms.Add(SQLParam.GetParam("@attr_choice_def", _attr_choice_def)); _Status = _stageProvider.ExecuteScalar <string>("SYNC_Map_Resident_Status", _sqlParms); isMatch = true; } catch (Exception ex) { EntityMessage(string.Format("Failed to map resident status for resident_def {0}. Error: {1}", _residentDef.ToString(), ex.Message), "ERROR"); } return(isMatch); }
public void RevokePermission(string mObject, string mOperation, string[] mRoles) { if (_App == null) { return; } //string HQL = "from role r where r.name in (:rolenames) AND r.AppID = :AppID"; //List<role> RoleLst = RoleSrv.GetbyHQuery(HQL, new SQLParam("rolenames", mRoles), new SQLParam("AppID", _App.AppID)); IroleService RoleSrv = new roleService(SessionFactoryConfigPath); string HQL = "from role r where r.AppID = :AppID AND r.name in ({0})"; string ParaStr = ":" + string.Join(",:", mRoles); HQL = string.Format(HQL, ParaStr); SQLParam[] paramList = new SQLParam[mRoles.Length + 1]; paramList[0] = new SQLParam("AppID", _App.AppID); for (int i = 0; i < mRoles.Length; i++) { paramList[i + 1] = new SQLParam(mRoles[i], mRoles[i]); } List <role> RoleLst = RoleSrv.GetbyHQuery(HQL, paramList); if (RoleLst == null || RoleLst.Count == 0) { return; } IpermissionService PermissionSrv = new permissionService(SessionFactoryConfigPath); permission TempPermission = PermissionSrv.GetPermission(mObject, mOperation, _App.AppID); if (TempPermission != null) { foreach (role r in RoleLst) { // not using r.Permissions because amount of roles allway is less than amount of Permissions. ->because perfomance if (TempPermission.Roles.Contains(r)) { TempPermission.Roles.Remove(r); } } PermissionSrv.CommitChanges(); } }
protected bool IsSubscriberMapped(string subscriberId) { bool isMapped = false; try { this._sqlParms = new List <SQLParam>(); this._sqlParms.Add(SQLParam.GetParam("@subscriber_id", subscriberId)); DataTable dtMapping = this._stageProvider.ExecuteDataSet("SYNC_Get_Subscriber_Mapping", this._sqlParms).Tables[0]; if (dtMapping.Rows.Count >= 1) { isMapped = true; } } catch { } return(isMapped); }
public void GrantPermission(string mObject, string mOperation, string[] mRoles) { if(_App==null)return ; string HQL = "from role r where r.AppID = :AppID AND r.name in ({0})"; string ParaStr = ":" + string.Join(",:", mRoles); HQL = string.Format(HQL, ParaStr); SQLParam[] paramList = new SQLParam[mRoles.Length + 1]; paramList[0] = new SQLParam("AppID", _App.AppID); for (int i = 0; i < mRoles.Length; i++) { paramList[i + 1] = new SQLParam(mRoles[i], mRoles[i]); } List<role> RoleLst = RoleSrv.GetbyHQuery(HQL, paramList); if (RoleLst == null || RoleLst.Count == 0) return; //Grant permission permission TempPermission = PermissionSrv.GetPermission(mObject, mOperation, _App.AppID); if (TempPermission == null) { objectRbac tempObject = ObjectSrv.GetByName(mObject, _App.AppID); operation tempOperation = OperationSrv.GetByName(mOperation, _App.AppID); if (tempObject == null || tempOperation == null) return; TempPermission = new permission(); TempPermission.AppID = _App.AppID; TempPermission.name = tempObject.name + ":" + tempOperation.name; TempPermission.ObjectRBAC = tempObject; TempPermission.Operation = tempOperation; TempPermission.Roles = new List<role>(); foreach (role r in RoleLst) { TempPermission.Roles.Add(r); } PermissionSrv.CreateNew(TempPermission); PermissionSrv.CommitChanges(); } else { foreach (role r in RoleLst) { if (!TempPermission.Roles.Contains(r)) TempPermission.Roles.Add(r); } PermissionSrv.CommitChanges(); } }
/// <summary> /// remove all oldrole assign for the permission and assign new [mRoles] for the permission /// </summary> /// <param name="mObject"></param> /// <param name="mOperation"></param> /// <param name="mRoles"></param> public void UpdatePermission(string mObject, string mOperation, string[] mRoles) { if (_App == null) return; string HQL = "from role r where r.AppID = :AppID AND r.name in ({0})" ; string ParaStr = ":" + string.Join(",:",mRoles); HQL = string.Format(HQL, ParaStr); SQLParam[] paramList = new SQLParam[mRoles.Length + 1]; paramList[0] = new SQLParam("AppID", _App.AppID); for(int i = 0;i< mRoles.Length;i++) { paramList[i + 1] = new SQLParam(mRoles[i],mRoles[i]); } //List<role> RoleLst = RoleSrv.GetbyHQuery(HQL, new SQLParam("rolenames", string.Join(",",mRoles)), new SQLParam("AppID", _App.AppID)); List<role> RoleLst = RoleSrv.GetbyHQuery(HQL, paramList); if (RoleLst == null || RoleLst.Count == 0) return; //Grant permission permission TempPermission = PermissionSrv.GetPermission(mObject, mOperation, _App.AppID); if (TempPermission != null) { List<role> TmpRolseLst = new List<role>(); foreach (role r in TempPermission.Roles) if (!RoleLst.Contains(r)) TmpRolseLst.Add(r); foreach (role r in TmpRolseLst) TempPermission.Roles.Remove(r); foreach (role r in RoleLst) if (!TempPermission.Roles.Contains(r))TempPermission.Roles.Add(r); PermissionSrv.CommitChanges(); } }
public void RevokePermission(string mObject, string mOperation, string[] mRoles) { if (_App == null) return; //string HQL = "from role r where r.name in (:rolenames) AND r.AppID = :AppID"; //List<role> RoleLst = RoleSrv.GetbyHQuery(HQL, new SQLParam("rolenames", mRoles), new SQLParam("AppID", _App.AppID)); string HQL = "from role r where r.AppID = :AppID AND r.name in ({0})"; string ParaStr = ":" + string.Join(",:", mRoles); HQL = string.Format(HQL, ParaStr); SQLParam[] paramList = new SQLParam[mRoles.Length + 1]; paramList[0] = new SQLParam("AppID", _App.AppID); for (int i = 0; i < mRoles.Length; i++) { paramList[i + 1] = new SQLParam(mRoles[i], mRoles[i]); } List<role> RoleLst = RoleSrv.GetbyHQuery(HQL, paramList); if (RoleLst == null || RoleLst.Count == 0) return; permission TempPermission = PermissionSrv.GetPermission(mObject, mOperation, _App.AppID); if (TempPermission != null) { foreach (role r in RoleLst) { // not using r.Permissions because amount of roles allway is less than amount of Permissions. ->because perfomance if (TempPermission.Roles.Contains(r)) { TempPermission.Roles.Remove(r); } } PermissionSrv.CommitChanges(); } }