public ClassTypes.Orders.Order UpdateOrder(ClassTypes.Orders.Order newOrder) { string bodyPara = JsonConvert.SerializeObject(newOrder, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); string response = CallAPI(string.Concat("orders/", newOrder.id.Value), Method.PUT, bodyPara); if (response.Contains("Error")) { return(null); } var order = JsonConvert.DeserializeObject <ClassTypes.Orders.Order>(response); return(order); }
public bool SyncOrders(string DBName, string APIKey, string APISecret, string APIURL, DateTime LastSyncedAt) { try { SetSyncLog(DBName, "SyncOrders Process Started...", true); DAL db = new DAL(DBName); DataTable dtOrders = db.execQuery("select ID, Status from eOrder where ModifiedAt >= '" + LastSyncedAt + "' and Status in ('Delivered','Cancelled','Returned')", System.Data.CommandType.Text, null); SetSyncLog(DBName, "Orders Found (EraConnect): " + dtOrders.Rows.Count, true); if (dtOrders != null && dtOrders.Rows.Count > 0) { WooWrapper woo = new WooWrapper(APIKey, APISecret, APIURL); foreach (DataRow row in dtOrders.Rows) { string DBStatus = row["Status"].ToString(); ClassTypes.Orders.Order ord = new ClassTypes.Orders.Order(); ord.id = int.Parse(row["id"].ToString()); ord.status = MapOrderStatus(DBStatus); if (woo.UpdateOrder(ord) == null) { SetSyncLog(DBName, "Error while updating order (EraLive): " + ord.id + ". Error: " + woo.error, true); } } } SetSyncLog(DBName, "SyncOrders Process Completed!", true); return(true); } catch (Exception ex) { string errorMessage = "Error: " + ex.Message; if (ex.InnerException != null && ex.InnerException.Message != string.Empty) { errorMessage += "| Inner Exception: " + ex.InnerException.Message; } SetSyncLog(DBName, "Error while Order Sync. " + errorMessage, true); error = ex.Message; return(false); } }