public NotificationsSummary GetNotificationsSummary(string userId)
        {
            var result = new NotificationsSummary();

            using (WriteLock.Read())
            {
                using (var connection = CreateConnection(true))
                {
                    using (var statement = connection.PrepareStatement("select Level from Notifications where UserId=@UserId and IsRead=@IsRead"))
                    {
                        statement.TryBind("@IsRead", false);
                        statement.TryBind("@UserId", userId.ToGuidBlob());

                        var levels = new List <NotificationLevel>();

                        foreach (var row in statement.ExecuteQuery())
                        {
                            levels.Add(GetLevel(row, 0));
                        }

                        result.UnreadCount = levels.Count;

                        if (levels.Count > 0)
                        {
                            result.MaxUnreadNotificationLevel = levels.Max();
                        }
                    }

                    return(result);
                }
            }
        }
        public NotificationsSummary GetNotificationsSummary(string userId)
        {
            var result = new NotificationsSummary();

            using (var cmd = _connection.CreateCommand())
            {
                cmd.CommandText = "select Level from Notifications where UserId=@UserId and IsRead=@IsRead";

                cmd.Parameters.Add(cmd, "@UserId", DbType.Guid).Value    = new Guid(userId);
                cmd.Parameters.Add(cmd, "@IsRead", DbType.Boolean).Value = false;

                using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                {
                    var levels = new List <NotificationLevel>();

                    while (reader.Read())
                    {
                        levels.Add(GetLevel(reader, 0));
                    }

                    result.UnreadCount = levels.Count;

                    if (levels.Count > 0)
                    {
                        result.MaxUnreadNotificationLevel = levels.Max();
                    }
                }

                return(result);
            }
        }