Question: I have a community site and I define the users who can contribute, visit, and admin for the community site.
Next I define two calendar lists inside the community list site collection.
Currently the contributors of the community site are contributes of the calendars. But my requirements are:-

1. That I need to define different permissions for users on the calendar and on the site collection.

I access the calendar list permission, and I select to stop permission inheritance. Then I removed the users from the contributor groups, but i I found that they were also removed from the community site list!.
So I need to know who I can have different permission levels for the community site and for the calendar lists. This is because the calendars should only be editable (add new events) by the site admin, while other users should only be able to seen the calendar and its evets. While inside the community site collection users can add, reply to discussion (they are contributors).

Answer: 
I found solution which runs perfectly in my case:

Use `LockedByUser` property of SPUser class.

The code `item.File.LockedByUser.LoginName` returns the user's log-in name who has locked the file. If it is not locked by anyone then it returns null.

The code is as below:

```
static void Main(string[] args)   
{
    using (SPSite siteCollection = new SPSite(@""))
    {
        using (SPWeb web = siteCollection.RootWeb)
        {
            using (web)
            {
                try
                {

                    SPList list = web.Lists["Documents"];

                    SPListItem item = list.Items[0];

                    userName = item.File.LockedByUser.LoginName;

                    if (string.IsNullOrEmpty(userName))
                    {
                        item["TESt"] = "Changed k";
                        item.Update();
                        Console.WriteLine("Changed successfully");
                    }

                    else
                    {
                        Console.WriteLine("Sorry File is open");
                    }                    

                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                    Console.ReadKey();
                }
                finally
                {
                    userName = string.Empty;   
                }
            }
        }

    }
}

```
If I understand your question correctly, you can check the Checked-Out status of the document.

```
if (item.Level == SPFileLevel.Checkout)
{
     // Your code here
}

```