public static void SetUserRights(this System.Windows.Controls.UserControl container, RolePermission permission, Button addButton, Button editButton, Button deleteButton, Button printButton, Button viewButton = null) { string sourcename = container.Tag.ToValueAsString(); try { if (sourcename.IsNotNullOrEmpty()) { if (addButton.IsNotNullOrEmpty()) { addButton.IsEnabled = permission.AddNew; } if (editButton.IsNotNullOrEmpty()) { editButton.IsEnabled = permission.Edit; } if (deleteButton.IsNotNullOrEmpty()) { deleteButton.IsEnabled = permission.Delete; } if (printButton.IsNotNullOrEmpty()) { printButton.IsEnabled = permission.Print; } if (viewButton.IsNotNullOrEmpty()) { viewButton.IsEnabled = permission.View; } } } catch (Exception ex) { throw ex.LogException(); } finally { } }
/// <summary> /// Used to set rights of the Action Buttones /// </summary> /// <param name="sourcename">Name of Form</param> /// <returns>RolePermission</returns> public RolePermission GetUserRights(string sourcename) { List <SEC_ROLE_OBJECT_PERMISSION> lstrolePermission = null; RolePermission permission = null; try { if (sourcename.IsNotNullOrEmpty()) { lstrolePermission = (from row in DB.SEC_ROLE_OBJECT_PERMISSION where ((Convert.ToBoolean(Convert.ToInt16(row.DELETE_FLAG)) == false) || (row.DELETE_FLAG == null)) && row.OBJECT_NAME.ToUpper() == sourcename.ToUpper() && row.ROLE_NAME.ToUpper() == userInformation.UserRole.ToUpper() select row).ToList <SEC_ROLE_OBJECT_PERMISSION>(); //if (!rolePermission.IsNotNullOrEmpty()) //{ // rolePermission = new SEC_ROLE_OBJECT_PERMISSION(); // rolePermission.PERM_ADD = true; // rolePermission.PERM_EDIT = true; // rolePermission.PERM_VIEW = true; // rolePermission.PERM_DELETE = true; // rolePermission.PERM_PRINT = true; //} permission = new RolePermission(); permission.SourceName = sourcename; permission.AddNew = false; permission.Edit = false; permission.View = false; permission.Delete = false; permission.Print = false; foreach (SEC_ROLE_OBJECT_PERMISSION objPermission in lstrolePermission) { if (objPermission.PERM_ADD.ToBooleanAsString() == true) { permission.AddNew = objPermission.PERM_ADD.ToBooleanAsString(); } if (objPermission.PERM_EDIT.ToBooleanAsString() == true) { permission.Edit = objPermission.PERM_EDIT.ToBooleanAsString(); } if (objPermission.PERM_VIEW.ToBooleanAsString() == true) { permission.View = objPermission.PERM_VIEW.ToBooleanAsString(); } if (objPermission.PERM_DELETE.ToBooleanAsString() == true) { permission.Delete = objPermission.PERM_DELETE.ToBooleanAsString(); } if (objPermission.PERM_PRINT.ToBooleanAsString() == true) { permission.Print = objPermission.PERM_PRINT.ToBooleanAsString(); } permission.Save = true; permission.Close = true; permission.Copy = true; permission.Search = true; permission.StandartNotes = true; permission.CostSheetSearch = true; permission.ProductSearch = true; permission.SimilarPartNumber = true; permission.ShowRelated = true; permission.ReleaseDocument = true; permission.UpdateOrderProcessing = true; permission.CreateCIReference = true; } } } catch (Exception ex) { throw ex.LogException(); } finally { if (lstrolePermission.IsNotNullOrEmpty()) { lstrolePermission.Clear(); } lstrolePermission = null; } return(permission); }