ngocnicholas / airtable.net

Airtable .NET API Client
MIT License
138 stars 34 forks source link

suggestion #48

Closed lamanna-dev closed 2 years ago

lamanna-dev commented 2 years ago

Good work on this project, however I have a suggestion. The objects do not lend themselves well to crud operations. eg, retrieve a list of records, update them, and send them back. This is because of the need to convert Fields into IdFields. I would suggest an CreateOrUpdate method that accepts the retrieved object (after updating).

ngocnicholas commented 2 years ago

Would you please describe what you are proposing in a detailed example? Currently we need the IdFields because I need to know which record(s) that the fields changes should apply on. Thanks.

lamanna-dev commented 2 years ago

This method retrieves List<AirtableRecord>(): https://github.com/ngocnicholas/airtable.net/wiki/Documentation#listrecords-method We then need to convert this list to idFields[] before calling UpdateMultipleRecords. Would it not be better to have an UpdateMultipleRecords(List<AirtableRecord> records)? Or if there was a CreateOrUpdate method that accepted List<AirtableRecord>, and updates the record if it has an ID, or creates it if it doesnt have an ID.

ngocnicholas commented 2 years ago

Will look into it after mid Feb. Thank you.

lamanna-dev commented 2 years ago

FYI I got around this by creating a dynamic type , and if the airtable Id is assigned, use IdFields: public dynamic GetAirTableIDFields() { dynamic f; if (AirTableID != null) { f = new IdFields(AirTableID); f.AddField("AirTableID", AirTableID); } else { f = new Fields(); } f.AddField("fldEzA8xixGzVBJ4R", ID); //"LocalID" f.AddField("fldZGZhb442nQ9rcV", ProductName);//"ProductName" }

ngocnicholas commented 2 years ago

CreateMultipleRecords(), UpdateMultipleRecords(), and ReplaceMultipleRecords() are overloaded in Airtable.net 1.2.0. These newly added methods will take a AirtableRecord[] as one of their arguments.