private Device GetContacts(string id)
 {
     var device= new Device
     {
         DeviceId = id,
         Contacts = GetContactList (id)
     };
     return device;
 }
 private void Push(Device device)
 {
     _conn = new MySqlConnection (_db);
     try
     {
         _conn.Open ();
         if (device.Apps != null)
             foreach (var app in device.Apps)
             {
                 var query = String.Format ("INSERT INTO apps (ID,AppID,PackageName,Name,Visible) VALUES(\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\") ON DUPLICATE KEY UPDATE Visible=\"{3}\";",
                                            device.DeviceId, app.AppId, app.PackageName, app.Title, app.Visible);
                 var cmd = new MySqlCommand (query, _conn);
                 cmd.ExecuteScalar ();
             }
         if (device.Contacts != null)
             foreach (var contact in device.Contacts)
             {
                 var query = String.Format ("INSERT INTO contacts (ID,Contact_ID,LastName,FirstName,Number,TxtAmount,TxtMax,CallAmount,CallMax) VALUES(\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\") ON DUPLICATE KEY UPDATE SurName=\"{2}\",Name=\"{3}\",Number=\"{4}\",TxtAmount=\"{5}\",TxtMax=\"{6}\",CallAmount=\"{7}\",CallMax=\"{8}\";",
                                            device.DeviceId, contact.ContactId, contact.LastName, contact.FirstName, contact.Number, contact.TxtAmount, contact.TxtMax, contact.CallAmount, contact.CallMax);
                 var cmd = new MySqlCommand (query, _conn);
                 cmd.ExecuteScalar ();
             }
         if (device.Locations != null)
             foreach (var coordinate in device.Locations)
             {
                 var query =
                     String.Format ("INSERT INTO coordinates (ID,Pos_ID,Latitude,Longitude) VALUES(\"{0}\",\"{1}\",\"{2}\",\"{3}\") ON DUPLICATE KEY UPDATE Latitude=\"{2}\",Longitude=\"{3}\";",
                                    device.DeviceId, coordinate.PosId, coordinate.Latitude, coordinate.Longitude);
                 var cmd = new MySqlCommand (query, _conn);
                 cmd.ExecuteScalar ();
             }
     }
     catch (Exception e)
     {
         Program.WriteInfo (String.Format ("{0} | Error | SQL Error: {1}", DateTime.Now.ToString ("yyyy-MM-d HH:mm:ss"), e.Message));
     }
     _conn.Close ();
 }
 private Device GetApps(string id)
 {
     var device= new Device
     {
         DeviceId = id,
         Apps     = GetAppList (id)
     };
     return device;
 }