public ObjResult Delete(int id, int user_id, string action)
        {
            connection = db.GetCon();
            connection.Open();

            ObjResult              objResult     = new ObjResult();
            UserPermission         obj           = new UserPermission();
            UserPermissionDao      dao           = new UserPermissionDao(connection, null);
            UserPermissionBusiness bus           = new UserPermissionBusiness(connection);
            List <string>          messages_list = new List <string>();

            //validações
            try
            {
                obj           = dao.GetById(id);
                messages_list = bus.Validate(obj, user_id, action);
                if (messages_list.Count > 0)
                {
                    objResult.resultStatus   = "error";
                    objResult.resultMessages = messages_list;
                    connection.Close();
                    return(objResult);
                }
            }
            finally
            {
                connection.Close();
            }

            NpgsqlTransaction transaction = null;

            try
            {
                connection.Open();
                transaction = connection.BeginTransaction();
                id          = new UserPermissionDao(connection, transaction).Delete(id);
                LogDao logDao = new LogDao(connection, transaction);
                logDao.Post(new Log(user_id, "UserPermission", action, id.ToString(), JsonConvert.SerializeObject(obj)));
                objResult.resultStatus = "success";
                objResult.data         = id;
                transaction.Commit();
            }
            catch (Exception ex)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw new Exception(ex.ToString());
            }
            finally
            {
                connection.Close();
            }
            return(objResult);
        }
        public ObjResult Get(int per_id, int user_id, string action)
        {
            connection = db.GetCon();
            connection.Open();

            ObjResult objResult                  = new ObjResult();
            UserPermissionBusiness bus           = new UserPermissionBusiness(connection);
            UserPermission         obj           = new UserPermission();
            List <string>          messages_list = new List <string>();
            UserPermissionDao      dao           = new UserPermissionDao(connection, null);

            //validações
            try
            {
                messages_list = bus.Validate(null, user_id, action);
                if (messages_list.Count > 0)
                {
                    objResult.resultStatus   = "error";
                    objResult.resultMessages = messages_list;
                    connection.Close();
                    return(objResult);
                }

                obj = dao.GetById(per_id);
                if (obj.per_id != 0)
                {
                    objResult.resultStatus = "success";
                    objResult.data         = obj;
                }
                else
                {
                    messages_list.Add("Registro não encontrado.");
                    objResult.resultStatus   = "error";
                    objResult.resultMessages = messages_list;
                }
            }
            finally
            {
                connection.Close();
            }

            return(objResult);
        }