Пример #1
0
        public static PermissionObject GetPermissionsByUser(string objectTypeId, int objectId, string userName)
        {
            if (string.IsNullOrEmpty(objectTypeId))
            {
                throw new ArgumentException(Resources.ShareData.MessageNullObjectTypeId);
            }

            if (objectId <= 0)
            {
                throw new ArgumentException(Resources.ShareData.MessageZeroObjectId);
            }

            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentException(Resources.ShareData.MessageErrorUserName);
            }

            PermissionObject theData = null;

            try
            {
                ObjectPermissionsTableAdapter localAdapter             = new ObjectPermissionsTableAdapter();
                PermissionObjectDS.ObjectPermissionsDataTable theTable = localAdapter.GetObjectPermissionsByUser(objectTypeId, objectId, userName);

                if (theTable != null && theTable.Rows.Count > 0)
                {
                    foreach (PermissionObjectDS.ObjectPermissionsRow theRow in theTable)
                    {
                        if (theData == null)
                        {
                            theData = FillRecord(theRow);
                            theData.TheActionList.Add(new ObjectAction.ObjectAction(theRow.objectActionID));
                        }
                        else
                        {
                            theData.TheActionList.Add(new ObjectAction.ObjectAction(theRow.objectActionID));
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                log.Error("Error en GetPermissionsByUser para objectTypeId: " + objectTypeId + ", objectId: " + objectId + " y userName: " + userName, exc);
                throw new ArgumentException(Resources.ShareData.MessageErrorPermissionsByUser);
            }

            return(theData);
        }
Пример #2
0
        public static List <PermissionObject> GetPermissionsByObject(string objectTypeId, int objectId)
        {
            if (string.IsNullOrEmpty(objectTypeId))
            {
                throw new ArgumentException(Resources.ShareData.MessageNullObjectTypeId);
            }

            if (objectId <= 0)
            {
                throw new ArgumentException(Resources.ShareData.MessageZeroObjectId);
            }

            List <PermissionObject> theList = new List <PermissionObject>();
            PermissionObject        theData = null;

            try
            {
                ObjectPermissionsTableAdapter localAdapter             = new ObjectPermissionsTableAdapter();
                PermissionObjectDS.ObjectPermissionsDataTable theTable = localAdapter.GetObjectPermissionsByObject(objectTypeId, objectId);

                if (theTable != null && theTable.Rows.Count > 0)
                {
                    foreach (PermissionObjectDS.ObjectPermissionsRow theRow in theTable)
                    {
                        if (!theList.Exists(i => i.UserName.Equals(theRow.username)))
                        {
                            theData = FillRecord(theRow);
                            theData.TheActionList.Add(new ObjectAction.ObjectAction(theRow.objectActionID));
                            theList.Add(theData);
                        }
                        else
                        {
                            theData = theList.Find(i => i.UserName.Equals(theRow.username));
                            theData.TheActionList.Add(new ObjectAction.ObjectAction(theRow.objectActionID));
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                log.Error("Error en GetPermissionsByObject para objectTypeId: " + objectTypeId + " y objectId: " + objectId, exc);
                throw new ArgumentException(Resources.ShareData.MessageErrorPermissionsByObject);
            }

            return(theList);
        }