/// <summary> /// Check if a group can be deleted. It check that it is not the last default group. /// </summary> /// <param name="groupID">Group Id</param> /// <param name="msg">Output message</param> /// <returns>True if can, false otherwise</returns> public bool CanDeleteGroup(int groupID, out string msg) { bool canDelete = false; MGGroup group = null; msg = ""; try { group = new MGGroup(); group = GetGroup(groupID); if (group == null) { msg = "Failed to get group for ID (" + groupID + "). Quitting"; Logger.LogError(5, msg); return(false); } //Checking if group if not default if (!group.IsDefault) { msg = "Group '" + group.Name + "' is not a 'Default Group' therefore can be deleted."; Logger.Log(msg); return(true); } canDelete = CanDeleteDefaultGroup(group, out msg); } catch (Exception ex) { msg = "Error checking if gorup with ID (" + groupID + ") can be deleted"; Logger.LogError(5, msg + " at: " + ex); return(false); } return(canDelete); }
private bool CheckIfGroupCanBeEdited(MGGroup newGroup, out string message) { bool canEdit = true; message = ""; //For given ID, If the new name is same as old Name then check if any of other values is changed //If the new Name is not same as that of existing name of same group, then check if the new name already exists for any other group MGGroup existingGroup = GetGroup(newGroup.ID); if (existingGroup.Name.Equals(newGroup.Name)) { if (existingGroup.Description.Equals(newGroup.Description)) { if (existingGroup.IsDefault == newGroup.IsDefault) { message = "All new values are identical to existing values."; canEdit = false; } } } else if (!CheckIfNewGroupNameIsValidInSystem(newGroup.Name)) { message = "The name '" + newGroup.Name + "' is not valid or already exists in the system. Please select another name."; canEdit = false; } return(canEdit); }
public bool ChangeUserToGroupAssociation(MGGroup group, List <int> usersIDs, AssociationTypes associationType) { bool ISChanged = true; DbInfo = new DatabaseWrapper(Lcf); string sql = ""; string partMSG = "'" + associationType + "ing' (" + usersIDs.Count + ") users to Group '" + group.Name + "'"; try { Logger.Log("Start " + partMSG); DbInfo.Connect(); foreach (int userID in usersIDs) { if (associationType == AssociationTypes.Assign) { sql = GroupQB.GetAssignGroupForUserSql(userID, group.ID); } else { sql = GroupQB.GetUnAssignGroupForUserSql(userID, group.ID); } bool success = false; int numChanged = DbInfo.ExecuteSQL(sql, ref success); if (numChanged == 0) { ISChanged = false; } } } catch (Exception ex) { Logger.LogError(5, "Error " + partMSG + " at: " + ex); return(false); } finally { if (ISChanged) { SecureContentWrapper.SecurityHasBeenModifiedThisSession = true; } if (DbInfo != null) { DbInfo.Disconnect(); } } return(ISChanged); }
/// <summary> /// Given a MG Group, Add to database /// </summary> /// <param name="group">Group to add</param> /// <returns>Return true if success, false otherwidr</returns> public bool AddGroup(MGGroup groupToAdd, out string message) { bool isAddSuccess = false; message = string.Empty; try { DbInfo = new DatabaseWrapper(Lcf); //Check if group can be added if (CheckIfGroupCanBeAdded(groupToAdd, out message)) { //Insert string sql = GroupQB.GetInsertGroupSql(groupToAdd); DbInfo.Connect(); bool success = false; if (DbInfo.ExecuteSQL(sql, ref success) == 1) { isAddSuccess = true; message = "Successfully added a group: '" + groupToAdd.Name + "'"; } else { message = "Failed to add a group: '" + groupToAdd.Name + "'"; } } } catch (Exception ex) { Logger.LogError(5, "Error adding a group at " + ex); message = "Error adding a Group " + groupToAdd.Name + ". Contact MGL."; isAddSuccess = false; } finally { if (isAddSuccess) { SecureContentWrapper.SecurityHasBeenModifiedThisSession = true; } if (DbInfo != null) { DbInfo.Disconnect(); } } return(isAddSuccess); }
private bool CanDeleteDefaultGroup(MGGroup group, out string msg) { bool canDelte = false; List <int> allDefaultGroupsIds = null; msg = ""; try { Logger.Log("Getting IDs of all default groups in the system...."); allDefaultGroupsIds = new List <int>(); allDefaultGroupsIds = GetDefaultGroupIDs(); if (allDefaultGroupsIds == null) { msg = "Error getting IDs of all Default Groups in the system. Quitting!"; Logger.LogError(5, msg); return(false); } if (allDefaultGroupsIds.Count == 0) { msg = "Can not delete. No default group entry is retreived from system. It is contradictory as the current selected group '" + group.Name + "'is a 'default group'."; Logger.LogError(5, msg); return(false); } if (allDefaultGroupsIds.Count == 1 && allDefaultGroupsIds.Contains(group.ID)) { msg = "Can not delete as the selected group is the only 'Default Group' in the system."; Logger.Log(msg); return(false); } if (allDefaultGroupsIds.Count > 1 && allDefaultGroupsIds.Contains(group.ID)) { msg = "Can delete the selected 'Default Group' as it is not 'the Only' in the system."; Logger.Log(msg); canDelte = true; } } catch (Exception ex) { msg = "Error checking if default gorup '" + group.Name + "' can be deleted"; Logger.LogError(5, msg + " at: " + ex); return(false); } return(canDelte); }
public bool EditGroup(MGGroup newGroup, out string message) { bool isAddSuccess = false; message = string.Empty; try { DbInfo = new DatabaseWrapper(Lcf); if (CheckIfGroupCanBeEdited(newGroup, out message)) { //Edit string sql = GroupQB.GetEditGroupSql(newGroup); DbInfo.Connect(); bool success = false; if (DbInfo.ExecuteSQL(sql, ref success) == 1) { isAddSuccess = true; message = "Successfully edited group: '" + newGroup.Name + "'"; } else { message = "Failed to edit group: '" + newGroup.Name + "'"; } } } catch (Exception ex) { Logger.LogError(5, "Error editing a group at " + ex); message = "Error editing a Group " + newGroup.Name + ". Contact MGL."; isAddSuccess = false; } finally { if (isAddSuccess) { SecureContentWrapper.SecurityHasBeenModifiedThisSession = true; } if (DbInfo != null) { DbInfo.Disconnect(); } } return(isAddSuccess); }
public MGGroup GetGroup(int id) { MGGroup result = null; GroupOperations groupHelper = null; try { groupHelper = new GroupOperations(Lcf); result = groupHelper.GetGroup(id); if (result == null) { Logger.LogWarning("Null Group found in the database for group ID = " + id.ToString()); } } catch (Exception ex) { Logger.LogError(5, "Error getting a group given its ID from database at: " + ex); return(null); } finally { if (groupHelper != null) { groupHelper.Finish(); } } return(result); }
public GroupPermissions GetGroupPermissions(MGGroup group, List <MGSecurityTag> groupContentSecKeyValPairs, List <MGSecurityTag> groupDisplaySecKeyValPairs, List <MGSecurityTag> groupFunctionSecKeyValPairs) { GroupPermissions groupPerms = null; try { groupPerms = new GroupPermissions(); groupPerms.GroupID = group.ID; if (groupContentSecKeyValPairs != null) { groupPerms.GroupContentPermissions = groupPerms.GetGroupContentPermissions(groupContentSecKeyValPairs); } if (groupDisplaySecKeyValPairs != null) { groupPerms.GroupDisplayPermissions = groupPerms.GetGroupDisplayPermissions(groupDisplaySecKeyValPairs); } if (groupFunctionSecKeyValPairs != null) { groupPerms.GroupFunctionPermissions = groupPerms.GetGroupFunctionPermissions(groupFunctionSecKeyValPairs); } } catch (Exception ex) { Logger.LogError(5, "Error getting group permissions for group with ID=" + group.ID + " at " + ex.StackTrace); groupPerms = null; } return(groupPerms); }
public MGGroup GetGroup(string name) { MGGroup result = null; GroupOperations groupHelper = null; Logger.Log("Start getting a group from databas where name of group is '" + name + "'."); try { groupHelper = new GroupOperations(Lcf); result = groupHelper.GetGroup(name); if (result == null) { Logger.LogWarning("Null Group found in the database for group Name = " + name); } } catch (Exception ex) { Logger.LogError(5, "Error getting a group from databas where name of group is '" + name + "'." + "at: " + ex); return(null); } finally { if (groupHelper != null) { groupHelper.Finish(); } } return(result); }
/// <summary> /// Checks if a group can be added. /// </summary> /// <param name="group"></param> /// <returns></returns> private bool CheckIfGroupCanBeAdded(MGGroup group, out string msg) { bool canAdd = true; msg = string.Empty; try { if (group == null || group.Name == null || group.Description == string.Empty) { Logger.LogError(5, "Null or empty value for new group is supplied. Check the inputs."); msg = "Null or empty input value. Please check that there is a valid value for gorup name and description "; return(false); } //Now check if Name is present in the database if (!CheckIfNewGroupNameIsValidInSystem(group.Name)) { msg = "The name '" + group.Name + "' is invalid or already exists in the system. Please select another name."; return(false); } } catch (Exception ex) { Logger.LogError(5, "Error while checking if a group can be added at: " + ex); canAdd = false; } return(canAdd); }
public GroupPermissions GetGroupPermissions(MGGroup group, List <MGSecurityTag> groupContentSecKeyValPairs) { return(GetGroupPermissions(group, groupContentSecKeyValPairs, null, null)); }
public GroupPermissions GetGroupPermissions(MGGroup group, GroupAdministration.AssociationTypes associationType) { if (group == null) { Logger.LogError(5, "NULL group found can not find permissions."); return(null); } GroupPermissions groupPermissions = null; GroupOperations groupOps = null; Logger.Log("Getting group permissions for group with ID " + group.ID + " and name " + group.Name + "..."); try { Logger.Log("Getting group security permission key value pairs ..."); // Extract the Application Level list of groups, along with the relevant cross references to Users and the content etc ... groupOps = new GroupOperations(Lcf); Logger.Log("Start getting groups->content lookup..."); List <MGSecurityTag> groupContentList = groupOps.GetGroupContentDictionary(group.ID, associationType); if (groupContentList == null) { Logger.LogError(5, "Got NULL list for group with name " + group.Name + " and ID " + group.ID + " groups->content lookup, abandoning getting group permissions!"); return(null); } Logger.Log("Start getting groups->display lookup..."); List <MGSecurityTag> groupDisplayList = groupOps.GetGroupDisplayDictionary(group.ID, associationType); if (groupDisplayList == null) { Logger.LogError(5, "Got NULL list for group with name " + group.Name + " and ID " + group.ID + " groups->display lookup, abandoning getting group permissions!"); return(null); } Logger.Log("Start getting groups->functionality lookup..."); List <MGSecurityTag> groupFunctionalityList = groupOps.GetGroupFunctionalityDictionary(group.ID, associationType); if (groupFunctionalityList == null) { Logger.LogError(5, "Got NULL list for group with name " + group.Name + " and ID " + group.ID + " groups->functionality lookup, abandoning getting group permissions!"); return(null); } Logger.Log("Finished getting group security permission key value pairs."); groupPermissions = GetGroupPermissions(group, groupContentList, groupDisplayList, groupFunctionalityList); if (groupPermissions == null) { Logger.LogError(5, "Failed to get group permissions for group with name " + group.Name + " and ID " + group.ID + "!"); return(null); } Logger.Log("Finished getting group permissions for group with name " + group.Name + " and ID " + group.ID + "."); } catch (Exception ex) { Logger.LogError(5, "Error getting all group permissions at " + ex.StackTrace); groupPermissions = null; } finally { if (groupOps != null) { groupOps.Finish(); } } return(groupPermissions); }
public GroupPermissions GetGroupPermissions(MGGroup group) { return(GetGroupPermissions(group, GroupAdministration.AssociationTypes.Assign)); }
public MasterEmployeeResult GetADMasterEmployeeByID(long MasterEmployeeId) { try { var _data = (from ME in _Context.ADMasterEmployees join SA in _Context.ADMasterSalutations on ME.MasterSalutationId equals SA.MasterSalutationId into SAGroup from SA in SAGroup.DefaultIfEmpty() join MG in _Context.ADMasterGenders on ME.Gender equals MG.MasterGenderId into MGGroup from MG in MGGroup.DefaultIfEmpty() join MD in _Context.ADMasterDesignations on ME.MasterDesignationId equals MD.MasterDesignationId into MDGroup from MD in MDGroup.DefaultIfEmpty() join DA in _Context.ADMasterDepartments on ME.MasterDepartmentId equals DA.MasterDepartmentId into DAGroup from DA in DAGroup.DefaultIfEmpty() join ME2 in _Context.ADMasterEmployees on ME.ReportingHeadId equals ME2.MasterEmployeeId into ME2Group from ME2 in ME2Group.DefaultIfEmpty() join MD2 in _Context.ADMasterDesignations on ME2.MasterDesignationId equals MD2.MasterDesignationId into MD2Group from MD2 in MD2Group.DefaultIfEmpty() join ET in _Context.ADMasterEmployeeTypes on ME.MasterEmployeeTypeId equals ET.MasterEmployeeTypeId into ETGroup from ET in ETGroup.DefaultIfEmpty() join TZ in _Context.ADMasterTimeZones on ME.MasterTimeZoneId equals TZ.MasterTimeZoneId into TZGroup from TZ in TZGroup.DefaultIfEmpty() join ES in _Context.ADMasterEmployeeStatus on ME.MasterEmployeeStatusId equals ES.MasterEmployeeStatusId into ESGroup from ES in ESGroup.DefaultIfEmpty() join CC in _Context.ADMasterCountries on ME.MasterCountryId equals CC.MasterCountryId into CCGroup from CC in CCGroup.DefaultIfEmpty() join MS in _Context.ADMasterStates on ME.MasterStateId equals MS.MasterStateId into MSGroup from MS in MSGroup.DefaultIfEmpty() join PT in _Context.ADMasterPaymentTypes on ME.MasterPaymentTypeId equals PT.MasterPaymentTypeId into PTGroup from PT in PTGroup.DefaultIfEmpty() join BA in _Context.ADMasterBankAccountTypes on ME.MasterBankAccountTypeId equals BA.MasterBankAccountTypeId into BAGroup from BA in BAGroup.DefaultIfEmpty() join MB in _Context.ADMasterBranches on ME.MasterBranchId equals MB.MasterBranchId into MBGroup from MB in MBGroup.DefaultIfEmpty() join MC in _Context.ADMasterCompanies on MB.MasterCompanyId equals MC.MasterCompanyId into MCGroup from MC in MCGroup.DefaultIfEmpty() where ME.MasterEmployeeId == MasterEmployeeId select new { ME.MasterEmployeeId, ME.EmployeeCode, ME.MasterSalutationId, SA.SalutationTitle, ME.EmployeeName, ME.DateOfBirth, ME.DateOfJoining, ME.Gender, MG.GenderTitle, ME.PANNo, ME.AadhaarNo, ME.MasterDesignationId, MD.DesignationTitle, ME.MasterDepartmentId, DA.DepartmentTitle, ME.ReportingHeadId, ReportingHeadTitle = ME2.EmployeeName, ReportingHeadDesignationTitle = MD2.DesignationTitle, ME.MasterEmployeeTypeId, ET.EmployeeTypeTitle, ME.MasterTimeZoneId, TZ.TimeZoneTitle, ME.MasterEmployeeStatusId, ES.EmployeeStatusTitle, ME.DateOfLeavingOrganisation, ME.Address1, ME.Address2, ME.MasterCountryId, CC.CountryTitle, ME.MasterStateId, MS.StateTitle, ME.City, ME.PinCode, ME.PhoneNumber, ME.MobileNumber, ME.Email, ME.MasterPaymentTypeId, PT.MasterPaymentTitle, ME.PaypalID, ME.PaypalLink, ME.IsPaypalAccountVerified, ME.MasterBankAccountTypeId, BA.MasterBankAccountTypeTitle, ME.BankName, ME.BankAccountNumber, ME.IFCSCode, ME.ShiftCode_RoutingNo_IBAN, ME.BankBranch, ME.BankCity, ME.BankAddress, ME.UploadBankDetail, ME.IsBankAccountVerified, ME.MasterBranchId, MB.BranchTitle, MB.MasterCompanyId, MC.CompanyTitle, MC.CompanyLogo, ME.IsActive }); var _Item = _data.Where(a => a.MasterEmployeeId == MasterEmployeeId).FirstOrDefault();; MasterEmployeeResult _MasterEmployeeResult = new MasterEmployeeResult(); if (_data != null) { _MasterEmployeeResult.MasterEmployeeId = _Item.MasterEmployeeId; _MasterEmployeeResult.EmployeeCode = _Item.EmployeeCode; _MasterEmployeeResult.MasterSalutationId = _Item.MasterSalutationId; _MasterEmployeeResult.SalutationTitle = _Item.SalutationTitle; _MasterEmployeeResult.EmployeeName = _Item.EmployeeName; _MasterEmployeeResult.DateOfJoining = _Item.DateOfJoining; _MasterEmployeeResult.DateOfBirth = _Item.DateOfBirth; _MasterEmployeeResult.Gender = _Item.Gender; _MasterEmployeeResult.GenderTitle = _Item.GenderTitle; _MasterEmployeeResult.PANNo = _Item.PANNo; _MasterEmployeeResult.AadhaarNo = _Item.AadhaarNo; _MasterEmployeeResult.MasterDesignationId = _Item.MasterDesignationId; _MasterEmployeeResult.DesignationTitle = _Item.DesignationTitle; _MasterEmployeeResult.MasterDepartmentId = _Item.MasterDepartmentId; _MasterEmployeeResult.DepartmentTitle = _Item.DepartmentTitle; _MasterEmployeeResult.ReportingHeadId = _Item.ReportingHeadId; _MasterEmployeeResult.ReportingHeadTitle = _Item.ReportingHeadTitle; _MasterEmployeeResult.ReportingHeadDesignationTitle = _Item.ReportingHeadDesignationTitle; _MasterEmployeeResult.MasterEmployeeTypeId = _Item.MasterEmployeeTypeId; _MasterEmployeeResult.EmployeeTypeTitle = _Item.EmployeeTypeTitle; _MasterEmployeeResult.MasterTimeZoneId = _Item.MasterTimeZoneId; _MasterEmployeeResult.TimeZoneTitle = _Item.TimeZoneTitle; _MasterEmployeeResult.MasterEmployeeStatusId = _Item.MasterEmployeeStatusId; _MasterEmployeeResult.EmployeeStatusTitle = _Item.EmployeeStatusTitle; _MasterEmployeeResult.DateOfLeavingOrganisation = _Item.DateOfLeavingOrganisation; _MasterEmployeeResult.Address1 = _Item.Address1; _MasterEmployeeResult.Address2 = _Item.Address2; _MasterEmployeeResult.MasterCountryId = _Item.MasterCountryId; _MasterEmployeeResult.CountryTitle = _Item.CountryTitle; _MasterEmployeeResult.MasterStateId = _Item.MasterStateId; _MasterEmployeeResult.StateTitle = _Item.StateTitle; _MasterEmployeeResult.City = _Item.City; _MasterEmployeeResult.PinCode = _Item.PinCode; _MasterEmployeeResult.MobileNumber = _Item.MobileNumber; _MasterEmployeeResult.PhoneNumber = _Item.PhoneNumber; _MasterEmployeeResult.Email = _Item.Email; _MasterEmployeeResult.MasterPaymentTypeId = _Item.MasterPaymentTypeId; _MasterEmployeeResult.PaymentTypeTitle = _Item.MasterPaymentTitle; _MasterEmployeeResult.PaypalID = _Item.PaypalID; _MasterEmployeeResult.PaypalLink = _Item.PaypalLink; _MasterEmployeeResult.IsPaypalAccountVerified = _Item.IsPaypalAccountVerified; _MasterEmployeeResult.MasterBankAccountTypeId = _Item.MasterBankAccountTypeId; _MasterEmployeeResult.BankName = _Item.BankName; _MasterEmployeeResult.BankAccountNumber = _Item.BankAccountNumber; _MasterEmployeeResult.IFCSCode = _Item.IFCSCode; _MasterEmployeeResult.ShiftCode_RoutingNo_IBAN = _Item.ShiftCode_RoutingNo_IBAN; _MasterEmployeeResult.BankBranch = _Item.BankBranch; _MasterEmployeeResult.BankCity = _Item.BankCity; _MasterEmployeeResult.BankAddress = _Item.BankAddress; _MasterEmployeeResult.UploadBankDetail = _Item.UploadBankDetail; _MasterEmployeeResult.IsBankAccountVerified = _Item.IsBankAccountVerified; _MasterEmployeeResult.MasterBranchId = _Item.MasterBranchId; _MasterEmployeeResult.BranchTitle = _Item.BranchTitle; _MasterEmployeeResult.MasterCompanyId = _Item.MasterCompanyId; _MasterEmployeeResult.CompanyTitle = _Item.CompanyTitle; _MasterEmployeeResult.CompanyLogo = _Item.CompanyLogo; _MasterEmployeeResult.IsActive = _Item.IsActive; _MasterEmployeeResult.ActiveColor = "green"; _MasterEmployeeResult.ActiveIcon = "glyphicon glyphicon-ok"; if (_MasterEmployeeResult.IsActive == false) { _MasterEmployeeResult.ActiveColor = "red"; _MasterEmployeeResult.ActiveIcon = "glyphicon glyphicon-remove"; } } return(_MasterEmployeeResult); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Get all groups from database. /// It checks if Description or IsDefault Column is missing in the table. If any is missing then skipping it. /// </summary> /// <param name="isFilterOutSuperGroup">Filter if to filer the supper group</param> /// <returns>List of Groups</returns> public List <MGGroup> GetAllGroups(bool isFilterOutSuperGroup) { List <MGGroup> groups = null; bool isDescriptionColExists = false; bool isIsDefaultColExists = false; bool isDescDefaultCols = false; bool isDefaultGroup = false; string sql = ""; string msg = "getting all groups from system. Filter supper group =" + isFilterOutSuperGroup; Logger.Log("Start " + msg); try { sql = "SELECT ID,GroupName,AllowDataEdit,AllowUserEdit"; //Checking if Description Column Exists or not if (dbInfo.ColumnExists(BaseSecurityOperations.tnGroups, DESC_COL_NAME)) { Logger.Log("Column '" + DESC_COL_NAME + "' exists in the table '" + BaseSecurityOperations.tnGroups + "'. Adding to sql..."); sql += "," + DESC_COL_NAME; isDescriptionColExists = true; } if (dbInfo.ColumnExists(BaseSecurityOperations.tnGroups, ISDEFAULT_COL_NAME)) { Logger.Log("Column '" + ISDEFAULT_COL_NAME + "' exists in the table '" + BaseSecurityOperations.tnGroups + "'. Adding to sql..."); sql += "," + ISDEFAULT_COL_NAME; isIsDefaultColExists = true; } sql += " FROM " + BaseSecurityOperations.tnGroups; //Setting flag if both Column Exists, This will define total number of column in Select Statement and will be read from dbInfo.GetDataList(sql) isDescDefaultCols = isDescriptionColExists && isIsDefaultColExists; if (isFilterOutSuperGroup) { sql += " WHERE GroupName <> '" + GroupAdministration.SUPER_USER_GROUP_NAME + "' "; } sql += " ORDER BY GroupName;"; List <string[]> data = dbInfo.GetDataList(sql); if (data == null) { Logger.LogError(8, "Error " + msg + ". Using sql = " + sql); return(null); } if (data.Count == 0) { Logger.Log("No group found in the system for sql = " + sql); return(groups = new List <MGGroup>()); } groups = new List <MGGroup>(); Logger.Log("Looping the data list to create list of MGGroups."); foreach (string[] row in data) { isDefaultGroup = false; bool allowDataEdit = (row[2].Equals("1")) ? true : false; bool allowUserEdit = (row[3].Equals("1")) ? true : false; MGGroup group = new MGGroup(int.Parse(row[0]), row[1], allowDataEdit, allowUserEdit); //If both Description and IsDefault Column exists then total number of column in Select Statement are 6 //4th Column is Description //5ht Column is IsDefault if (isDescDefaultCols) { if (row.Length > 4) { if (row[4] != null) { group.Description = row[4]; } if (row[5] != null) { isDefaultGroup = (row[5].Equals("1")) ? true : false; group.IsDefault = isDefaultGroup; } else { Logger.LogWarning("Invalid value found for column " + ISDEFAULT_COL_NAME); } } } else { if (isDescriptionColExists) { if (row.Length > 4) { if (row[4] != null) { group.Description = row[4]; } } } if (isIsDefaultColExists) { if (row.Length > 4) { if (row[4] != null) { isDefaultGroup = (row[4].Equals("1")) ? true : false; group.IsDefault = isDefaultGroup; } } } } groups.Add(group); } // Logger.LogList = dbInfo.GetErrors(), thisClassName, "GetAllFeatures"); } catch (Exception ex) { Logger.LogError(8, "Error " + msg + ". At " + ex); Logger.LogError(8, thisClassName + " GetAllGroups:" + ex.ToString()); return(null); } return(groups); }
//--------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Get a group from database given group ID. /// It checks if Description or IsDefault Column is missing in the table. If any is missing then skipping it. /// </summary> /// <returns>Group Object</returns> public MGGroup GetGroup(int groupID) { MGGroup group = null; string sql = ""; bool isDescriptionColExists = false; bool isIsDefaultColExists = false; bool isDescDefaultCols = false; string msg = "getting group from system where Group ID = " + groupID; Logger.Log("Start " + msg); try { sql = "SELECT ID,GroupName,AllowDataEdit,AllowUserEdit"; //Checking if Description Column Exists or not if (dbInfo.ColumnExists(BaseSecurityOperations.tnGroups, DESC_COL_NAME)) { Logger.Log("Column '" + DESC_COL_NAME + "' exists in the table '" + BaseSecurityOperations.tnGroups + "'. Adding to sql..."); sql += "," + DESC_COL_NAME; isDescriptionColExists = true; } if (dbInfo.ColumnExists(BaseSecurityOperations.tnGroups, ISDEFAULT_COL_NAME)) { Logger.Log("Column '" + ISDEFAULT_COL_NAME + "' exists in the table '" + BaseSecurityOperations.tnGroups + "'. Adding to sql..."); sql += "," + ISDEFAULT_COL_NAME; isIsDefaultColExists = true; } sql += " FROM " + BaseSecurityOperations.tnGroups; //Setting flag if both Column Exists, This will define total number of column in Select Statement and will be read from dbInfo.GetDataList(sql) isDescDefaultCols = isDescriptionColExists && isIsDefaultColExists; sql += " WHERE ID = '" + groupID + "';"; string[] row = dbInfo.GetDataSingleRecord(sql); if (row == null) { Logger.LogError(5, "Error " + msg + ". Using sql = " + sql); return(null); } if (row.Length == 0) { Logger.Log("No group found in the system for sql = " + sql); return(group = new MGGroup()); } Logger.Log("Creating a group object and setting properties."); bool allowDataEdit = (row[2].Equals("1")) ? true : false; bool allowUserEdit = (row[3].Equals("1")) ? true : false; group = new MGGroup(int.Parse(row[0]), row[1], allowDataEdit, allowUserEdit); //If both Description and IsDefault Column exists then total number of column in Select Statement are 6 //4th Column is Description //5ht Column is IsDefault bool isDefaultGroup = false; if (isDescDefaultCols) { if (row.Length > 4) { if (row[4] != null) { group.Description = row[4]; } if (row[5] != null) { isDefaultGroup = (row[5].Equals("1")) ? true : false; group.IsDefault = isDefaultGroup; } else { Logger.LogWarning("Invalid value found for column " + ISDEFAULT_COL_NAME); } } } else { if (isDescriptionColExists) { if (row.Length > 4) { if (row[4] != null) { group.Description = row[4]; } } } if (isIsDefaultColExists) { if (row.Length > 4) { if (row[4] != null) { isDefaultGroup = (row[4].Equals("1")) ? true : false; group.IsDefault = isDefaultGroup; } } } } } catch (Exception ex) { Logger.LogError(5, "Error " + msg + ex); return(null); } return(group); }
/// <summary> /// Get Users for a given Group. It populate only (3) three User Information (UserName, JobTitle, Email) /// </summary> /// <param name="group">Group for which to find users.</param> /// <param name="associationTypes">Assigned and Unassigned user to group.</param> /// <returns></returns> public List <MGUser> GetUsersForAGroup(MGGroup group, string searchString, AssociationTypes associationTypes) { List <MGUser> result = null; IDataReader reader = null; string strUserID = null; int userID = -1; string sql = ""; string msgPart = "getting users which are '" + associationTypes + "ed' to Group '" + group.Name + "'"; bool isLockAcquired = Monitor.TryEnter(UserAdministration.USER_ADMIN_LOCK_OBJ, UserAdministration.USER_ADMIN_LOCK_TIMEOUT); if (isLockAcquired) { try { Logger.Log("Start " + msgPart); DbInfo = new DatabaseWrapper(Lcf); DbInfo.Connect(); sql = GroupQB.GetSelectUsersForAGroupSql(group.ID, searchString, associationTypes); reader = DbInfo.RunSqlReader(sql); if (reader == null) { Logger.LogError(5, "Quitting, failed " + msgPart + " with sql : " + sql); return(null); } result = new List <MGUser>(); while (reader.Read()) { strUserID = null; userID = -1; MGUser user = new MGUser(); //Get USER ID if (reader[GroupQB.USER_ID_GENERAL_COL] != System.DBNull.Value) { strUserID = reader[GroupQB.USER_ID_GENERAL_COL].ToString(); if (!int.TryParse(strUserID, out userID)) { userID = -1; Logger.LogError(5, "Error parsing user ID into integer. Quitting"); return(null); } } user.ID = userID; //Get User Name if (reader[GroupQB.USER_NAME_COL] != System.DBNull.Value) { user.Username = SecureStringWrapper.Encrypt((string)reader[GroupQB.USER_NAME_COL]); } else { Logger.LogWarning("Null or empty User is found for ID =" + user.ID + ". Please check the database!"); user.Username = SecureStringWrapper.Encrypt(""); } //Get User EMAIL if (reader[GroupQB.USER_EMAIL_COL] != System.DBNull.Value) { user.Email = SecureStringWrapper.Encrypt((string)reader[GroupQB.USER_EMAIL_COL]); } else { Logger.LogWarning("Null or empty Email is found for ID =" + user.ID + ". Please check the database!"); user.Email = SecureStringWrapper.Encrypt(""); } //Get User Job Title if (reader[GroupQB.USER_JOBTITLE_COL] != System.DBNull.Value) { user.JobTitle = SecureStringWrapper.Encrypt((string)reader[GroupQB.USER_JOBTITLE_COL]); } else { //Logger.LogWarning("Null or empty job title is found for ID =" + user.ID + ". Please check the database!"); user.JobTitle = SecureStringWrapper.Encrypt(""); } result.Add(user); } } catch (Exception ex) { Logger.LogError(5, "Error " + msgPart + " at: " + ex); return(null); } finally { Monitor.Exit(UserAdministration.USER_ADMIN_LOCK_OBJ); if (reader != null && !reader.IsClosed) { reader.Close(); } if (DbInfo != null) { DbInfo.Disconnect(); } } } else { Logger.LogError(5, "Failed to get exclusive lock in GetUsersForAGroup when " + msgPart); return(null); } return(result); }