Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jul 25, 2012 @ 15:49
    Bo Damgaard Mortensen
    0

    Check the state of a record from C#

    Hi all,

    I'm currently working on a project where I'm using Contour. On a UserControl, I need to check if a record has been approved or not. 

    I've tried to make use of the State property on the Record object, but without any luck.

    Is there any way to, programaticall, check the current state of a record? :-)

    Thanks in advance.

    All the best,

    Bo

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jul 26, 2012 @ 10:13
    Bo Damgaard Mortensen
    1

    I went and wrote my own helper method for it:

    public bool IsRecordApproved(Guid recordGuid)
            {
                try
                {
                    bool result = false;
                    string sql = "SELECT state FROM UFRecords WHERE Id = @recordId";
                    var reader = umbraco.BusinessLogic.Application.SqlHelper.ExecuteReader(sql, SqlParameter("@recordId", recordGuid.ToString()));
                    while(reader.Read())
                    {
                        int state = reader.GetInt("state");
                        if (state == 4)
                            result = true;
                    }
    
                    return result;
                }
                catch (Exception)
                {
                    // If anything went wrong, we just want to approve the record
                    return false;
                }
            }
    
    IParameter SqlParameter(string parameterName, object value)
    {
         return (umbraco.BusinessLogic.Application.SqlHelper.CreateParameter(parameterName, value));
    }
    

     

Please Sign in or register to post replies

Write your reply to:

Draft