public int UpdateValue(string variableName, string value, EnumVariableType type, string userId = null)
        {
            SystemVariable variable = null;

            using (var transaction = db.BeginTransaction())
            {
                try
                {
                    variable = db.SystemVariables.FirstOrDefault(x => x.Name == variableName && x.Type == type && x.UserId == userId);

                    if (variable == null)
                    {
                        variable = new SystemVariable {
                            Name = variableName, Type = type, UserId = userId, Value = value
                        };
                    }

                    variable.Value = value;
                    AddOrUpdate(variable);
                    transaction.Commit();
                }
                catch
                {
                    variable = new SystemVariable {
                        Id = 0
                    };
                    transaction.Rollback();
                }
            }

            return(variable.Id);
        }