Exemple #1
0
 public string GetActivationCode(NewClientApp x)
 {
     try {
         if (string.IsNullOrEmpty(x.code))
         {
             string path = Server.MapPath(string.Format("~/App_Data/{0}", dataBase));
             db.CreateGlobalDataBase(path, db.clientapp);
             x.code = CreateActivationCode();
             if (x.code == null)
             {
                 return(null);
             }
             if (string.IsNullOrEmpty(x.id))
             {
                 x.id = Guid.NewGuid().ToString();
             }
             SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0}", path));
             connection.Open();
             string        sql     = string.Format(@"BEGIN;
                 INSERT OR REPLACE INTO clientapp (id, clientId, userId, code, lang)
                 VALUES ('{0}', '{1}', '{2}', '{3}', '{4}');
                 COMMIT;", x.id, x.clientId, x.userId, x.code, x.lang);
             SQLiteCommand command = new SQLiteCommand(sql, connection);
             command.ExecuteNonQuery();
             connection.Close();
         }
         return(JsonConvert.SerializeObject(x, Formatting.None));
     } catch (Exception e) {
         return(null);
     }
 }
Exemple #2
0
    public string Activate(string code)
    {
        NewClientApp x = new NewClientApp();

        try {
            string path = Server.MapPath(string.Format("~/App_Data/{0}", dataBase));
            //db.CreateGlobalDataBase(path, db.clientapp);
            using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0}", path))) {
                connection.Open();
                string sql = string.Format(@"SELECT id, clientId, userId, code, lang FROM clientapp WHERE code = '{0}'", code);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            x.id       = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
                            x.clientId = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
                            x.userId   = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                            x.code     = reader.GetValue(3) == DBNull.Value ? "" : reader.GetString(3);
                            x.lang     = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4);
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(x, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, code, null, "ClientApp", "Activate");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }
Exemple #3
0
 private NewClientApp GetCode(string clientId)
 {
     try {
         string path = Server.MapPath(string.Format("~/App_Data/{0}", dataBase));
         db.CreateGlobalDataBase(path, db.clientapp);
         NewClientApp x = new NewClientApp();
         using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0}", path))) {
             connection.Open();
             string sql = string.Format(@"SELECT id, clientId, userId, code, lang FROM clientapp WHERE clientId = '{0}'", clientId);
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 using (SQLiteDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         x.id       = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0);
                         x.clientId = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
                         x.userId   = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                         x.code     = reader.GetValue(3) == DBNull.Value ? "" : reader.GetString(3);
                         x.lang     = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4);
                     }
                 }
             }
             connection.Close();
         }
         return(x);
     } catch (Exception e) { return(new NewClientApp()); }
 }
Exemple #4
0
    public string Get(string clientId)
    {
        NewClientApp x = new NewClientApp();

        try {
            if (string.IsNullOrWhiteSpace(clientId))
            {
                return(JsonConvert.SerializeObject(x, Formatting.None));
            }
            x = GetCode(clientId);
            return(JsonConvert.SerializeObject(x, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, null, clientId, "ClientApp", "Get");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }