Created
July 10, 2015 08:33
-
-
Save salami-art/6d0d3144cf0bfd578964 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string Aggiorna(string classe, string parametri) | |
{ | |
int id; | |
string aggiornato = ""; | |
ClasseCollegataAUnRecordSuDB_Base classeCollegata = ritornaIstanza(classe); | |
JObject par = JObject.Parse(parametri); | |
var oggettoParametri = par.ToObject<Dictionary<string, dynamic>>(); | |
var chiavi = oggettoParametri.Keys.ToArray(); | |
if (!int.TryParse("0" + (string)oggettoParametri["Id"], out id)) | |
id = 0; | |
if( id > 0) | |
classeCollegata.leggiDatiDaDB(id); | |
if (classeCollegata.haGliStessiParametri(chiavi)); | |
{ | |
Type type = classeCollegata.GetType(); | |
// assegna le proprietà alla classe programmaticamente | |
foreach (KeyValuePair<string, dynamic> entry in oggettoParametri) | |
{ | |
PropertyInfo prop = type.GetProperty(entry.Key); | |
Type propertyType = prop.PropertyType; | |
prop.SetValue(classeCollegata, Convert.ChangeType(entry.Value, propertyType)); | |
} | |
} | |
//classeCollegata.SalvaSuDB(); | |
return aggiornato; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment