Esempio n. 1
0
        public bool ExistUserAccess(UserAccess uPerm, string userId)
        {
            Boolean         retVal = false;
            MySqlConnection con    = new MySqlConnection(DbCon.connectionString);
            MySqlDataReader dr     = null;
            MySqlCommand    cmd;

            string query = "SELECT `userid` `useraccess` WHERE userid=@userid AND mainid =@mainid ";


            try
            {
                con.Open();
                cmd = new MySqlCommand(query, con);
                cmd.Parameters.AddWithValue("@userid", uPerm.UserId);
                cmd.Parameters.AddWithValue("@mainid", uPerm.MainId);

                //int affecRow = cmd.ExecuteNonQuery();
                //new AuditLogService().AddAuditLog("ADD USER PERMISSION", userId, new UserService().GetUserName(userId), query, DateTime.Now);
                dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    retVal = true;
                }
            }
            catch (MySqlException ex)
            {
                // new AuditLogService().AddAuditLog("ERROR ADD USER PERMISSION", userId, new UserService().GetUserName(userId), ex.Message, DateTime.Now);
                string errorString = ex.Message;
            }
            catch (Exception ex)
            {
                //new AuditLogService().AddAuditLog("ERROR ADD USER PERMISSION", userId, new UserService().GetUserName(userId), ex.Message, DateTime.Now);
                string errorString = ex.Message;
            }
            finally
            {
                con.Close();
            }

            return(retVal);
        }
Esempio n. 2
0
        public bool AddUserAccess(UserAccess uPerm, string userId)
        {
            Boolean         retVal = false;
            MySqlConnection con    = new MySqlConnection(DbCon.connectionString);
            MySqlCommand    cmd;

            string query = "INSERT INTO `useraccess`(`userid`, `mainid`, `dateCreated`, `dateModify`) VALUES (@userid,@mainid,@dateCreated,@dateModify)";


            try
            {
                con.Open();
                cmd = new MySqlCommand(query, con);
                cmd.Parameters.AddWithValue("@userid", uPerm.UserId);
                cmd.Parameters.AddWithValue("@mainid", uPerm.MainId);
                cmd.Parameters.AddWithValue("@dateCreated", uPerm.DateCreated);
                cmd.Parameters.AddWithValue("@dateModify", uPerm.LastModify);
                int affecRow = cmd.ExecuteNonQuery();
                //new AuditLogService().AddAuditLog("ADD USER PERMISSION", userId, new UserService().GetUserName(userId), query, DateTime.Now);
                if (affecRow > 0)
                {
                    retVal = true;
                }
            }
            catch (MySqlException ex)
            {
                // new AuditLogService().AddAuditLog("ERROR ADD USER PERMISSION", userId, new UserService().GetUserName(userId), ex.Message, DateTime.Now);
                string errorString = ex.Message;
            }
            catch (Exception ex)
            {
                //new AuditLogService().AddAuditLog("ERROR ADD USER PERMISSION", userId, new UserService().GetUserName(userId), ex.Message, DateTime.Now);
                string errorString = ex.Message;
            }
            finally
            {
                con.Close();
            }

            return(retVal);
        }