public bool PermissionExists(Attribute.PermissionAttribute permissionAttribute) { UserPermissionTree userPermissionTree = null; Logger.Debug(DebugString.Format(Messages.PermissionStart, permissionAttribute.PermissionID)); try { userPermissionTree = (UserPermissionTree)company.GetBusinessObject(BoObjectTypes.oUserPermissionTree); if (userPermissionTree.GetByKey(permissionAttribute.PermissionID)) { return(true); } else { return(false); } } catch (Exception e) { Logger.Error(String.Format(Messages.UpdateOrSavePermissionError, e.Message), e); throw e; } finally { if (userPermissionTree != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(userPermissionTree); } Logger.Debug(DebugString.Format(Messages.PermissionEnd, permissionAttribute.PermissionID)); } }
public string CreateUserPermission(PermissionModel model, bool recreate = false, bool AddPermissionsToUsers = true) { UserPermissionTree oUserPermissionTree = (UserPermissionTree)SBOApp.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserPermissionTree); string msg = String.Empty; try { bool update = oUserPermissionTree.GetByKey(model.PermissionID); if (update && recreate) { int permission = oUserPermissionTree.Remove(); } oUserPermissionTree.PermissionID = model.PermissionID; oUserPermissionTree.Name = model.Name; oUserPermissionTree.Options = model.Options; oUserPermissionTree.IsItem = model.IsItem; if (!String.IsNullOrEmpty(model.ParentId)) { oUserPermissionTree.ParentID = model.ParentId; } if (model.IsItem == SAPbobsCOM.BoYesNoEnum.tYES && !String.IsNullOrEmpty(model.FormType)) { bool formExists = false; int i; for (i = 0; i < oUserPermissionTree.UserPermissionForms.Count; i++) { oUserPermissionTree.UserPermissionForms.SetCurrentLine(i); if (oUserPermissionTree.UserPermissionForms.FormType == model.FormType) { formExists = true; msg = String.Format("Permissão {0} - {1} já existe", model.PermissionID, model.Name); } } if (!formExists) { if (!String.IsNullOrEmpty(oUserPermissionTree.UserPermissionForms.FormType)) { oUserPermissionTree.UserPermissionForms.Add(); } oUserPermissionTree.UserPermissionForms.FormType = model.FormType; } } int error = 0; error = oUserPermissionTree.Add(); if (update && !recreate) { error = oUserPermissionTree.Update(); } else { error = oUserPermissionTree.Add(); } if (error != 0) { msg = ErrorController.GetLastErrorDescription(); } else if (AddPermissionsToUsers) { msg = this.SetPermissionForAllUsers(model.PermissionID); } } catch (Exception e) { msg = "Erro geral ao criar permissão: " + e.Message; } finally { Marshal.ReleaseComObject(oUserPermissionTree); oUserPermissionTree = null; } return(msg); }